我有Spinner的一些物品。有些项目有长文本,所以它没有出现在微调器上。如何在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" />
答案 1 :(得分:0)
你必须创建一些自定义微调器
Adapter.setDropDownViewResource(R.layout.spinner);
答案 2 :(得分:0)
您必须创建自定义微调器
String[] spinnerValues = { "1-10", "10-100", "100-200","200-500", "500-1000","1000-2000","2000-5000","No. of Employees" };
Private Spinner _spin;
_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.
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;
}
}
<?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" />