2011-08-10 50 views

回答

0

你必須創建一些自定義的微調

Adapter.setDropDownViewResource(R.layout.spinner);

+0

謝謝你...你給我一個例子? –

1

對於微調,你必須創建XML文件

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/text1" 
style="android:attr/dropDownItemStyle" 
android:singleLine="true" 
android:layout_width="fill_parent" 
android:layout_height="45px" 
android:ellipsize="marquee" 
android:textColor="#000000" 
android:gravity="center_vertical" /> 
0

,你必須創建一個自定義飛旋在活動

全局

String[] spinnerValues = { "1-10", "10-100", "100-200","200-500", "500-1000","1000-2000","2000-5000","No. of Employees" }; 
Private Spinner _spin; 

在OnCreate中

_spin= (Spinner) findViewById(R.id.your_spinner_id); 
_spin.setAdapter(new MyAdapter(this,R.layout.inflator_file,spinnerValues)); 
_spin.setSelection(spinnerValues.length - 1); // used to set a prompt in dropdown spinner. 

適配器c LASS

public class MyAdapter extends ArrayAdapter<String> { 

    public MyAdapter(Context ctx, int txtViewResourceId, String[] objects) { 
     super(ctx, txtViewResourceId, objects); 
    } 

    @Override 
    public View getDropDownView(int position, View cnvtView, ViewGroup prnt) { 
     return getCustomView(position, cnvtView, prnt); 
    } 
    @Override 
    public View getView(int pos, View cnvtView, ViewGroup prnt) { 
     return getCustomView(pos, cnvtView, prnt); 
    } 
    public View getCustomView(int position, View convertView,ViewGroup parent) { 
     LayoutInflater inflater = getLayoutInflater(); 
     View mySpinner = inflater.inflate(R.layout.inflator_file, parent,false); 
     TextView main_text = (TextView) mySpinner.findViewById(R.id.textone); 
     main_text.setText(spinnerValues[position]); 
     return mySpinner; 
    } 
} 

inflater_file.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/textone" 
android:singleLine="true" 
android:textColor="#9c9a9b" 
android:gravity="left|center" 
android:typeface="serif" 
android:paddingLeft="8dp" 
android:textSize="14sp" 
android:layout_width="fill_parent" 
android:layout_height="24dp" 
android:ellipsize="marquee" /> 
相關問題