activity_main.xml文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="请选择:" android:textSize="35px" android:textColor="#00aa00" android:id="@+id/t1"/> <Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/spinner01"/> </LinearLayout> MainActivity.java文件 import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.*; import android.widget.AdapterView.OnItemSelectedListener; import android.os.Build; public class MainActivity extends ActionBarActivity { private static String[]m={"A型","B型","AB型","o型","其他"}; private TextView textview; private Spinner spinner; private ArrayAdapter<String> adapter; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textview=(TextView)findViewById(R.id.t1); spinner=(Spinner)findViewById(R.id.spinner01); adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,m); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new SpinnerSelectdeListener()); } class SpinnerSelectdeListener implements OnItemSelectedListener{ @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { textview.setText("您的血型是"+m[arg2]); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 现在模拟器的效果是这样的 |
|
40分
#1 |
textview不要设置fill parent
|
40分
#2 |
TextView的高度fill_parent 改成wrap_content
|
40分
#3 |
textview占了全屏,改成wrap_content
|