我希望我的微调器看起来像这样
只有最上面的标题应该有图像和文本。剩余的下拉菜单应该只有文本。 谁能帮我做这个。
我试过了..
我的xml文件
<Spinner android:id="@+id/spinner1"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_below="@id/view"
android:layout_marginLeft="35dp"
android:layout_marginTop="20dp"
android:background="@drawable/grey_btn"
android:popupBackground="@drawable/drop_down_background"
android:spinnerMode="dropdown" />
然后
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(mContext, R.drawable.spinner_text,R.id.customtextview,arr1); adapter1.setDropDownViewResource(R.drawable.drop_down); s1.setAdapter(adapter1);
最佳答案
您应该在适配器中同时拥有 getView 和 getDropDownView。通过这种方式,您可以为所选项目和列表的其余部分指定不同的外观。
在获取 View 中:
textView = (TextView) convertView.findViewById(R.id.spinner_item_text);
imageView = (ImageView) convertView.findViewById(R.id.spinner_item_image);
textView.setVisibility(ImageView.VISIBLE);
imageView.setVisibility(ImageView.VISIBLE);
在 getDropDownView 中:
textView = (TextView) convertView.findViewById(R.id.spinner_item_text);
imageView = (ImageView) convertView.findViewById(R.id.spinner_item_image);
textView.setVisibility(ImageView.VISIBLE);
imageView.setVisibility(ImageView.INVISIBLE);
关于android - 带有图像和文本的微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16667129/