Spinner的实现效果如下
代码如下
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"></Spinner>
</RelativeLayout>
public class MainActivity extends Activity {
private Spinner mSpinner;
private String[] array={"view_text","view_edit","view_list","layout_linear","layout_relative","layout_frame","layout_abosolutely","button"};
private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSpinner= (Spinner) findViewById(R.id.spinner);
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,array);
mSpinner.setAdapter(adapter);
}
}