spinner居中下拉显示

layout:

     
    android:layout_width="100dp"
    android:layout_height="33dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="@drawable/bg"
    android:gravity="center|center_horizontal"
    android:spinnerMode="dropdown"
     />

说明:spinnerMode 设置下拉弹出样式  


java:

private static final String[] sSpiner={"aa","bb","cc"};
private ArrayAdapter adapter;


sp=(Spinner)findViewById(R.id.spTitle);
adapter = new ArrayAdapter(this, R.layout.spinnerlayout,sSpiner);

//设置下拉列表的风格
adapter.setDropDownViewResource(R.layout.spinnerlayout);
sp.setAdapter(adapter);
sp.setSelection(0);
sp.setOnItemSelectedListener(new SpinnerSelectedListener());

自定义居中显示文本框:

spinnerlayout.xml

xml version = "1.0" encoding = "utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:gravity="center" />


你可能感兴趣的:(android自定义控件)