如何重新大小的项目在微调与选择题的高度? [英] How to re size the Height of the Items in Spinner with multiple choice?
问题描述
我只是显示了微调
有选择题在此基础上的计算器的答案(见@Destil答案)。在这里,我的问题是我不能重新大小的项目的高度的微调有多个选择。如何重新大小每个项目的高度?
I just showing the spinner
with multiple choice based on this stackoverflow answer(see @Destil answer). Here my problem is I can't re size the Height of the items in Spinner with multiple choice. How to re size the Height of each Items?
推荐答案
据我所知,你将不得不使用自定义适配器,并覆盖getDropDown和getView方法。您可以自定义每个项目自定义布局。
As i know, you will have to use a custom adapter, and override the getDropDown and the getView methods. You will be able to customize each item customizing the layout.
嗯......话是很好的,例如更好,尝试这样的事情:
Well... words are good, example better, try something like that :
public class CustomStringArrayAdapter extends ArrayAdapter<String>
{
private Activity myActivity;
public CustomStringArrayAdapter(Context context, int layoutResourceId, int textViewResourceId, List<String> objects, Activity act)
{
super(context, layoutResourceId, textViewResourceId, objects);
this.myActivity = act;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = myActivity.getLayoutInflater();
View row = inflater.inflate(R.layout.spinner_layout, parent, false);
TextView label = (TextView) row.findViewById(R.id.spinner_textview);
label.setText(getItem(position));
LinearLayout layout = (LinearLayout) row.findViewById(R.id.spinner_linear_layout);
return row;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = myActivity.getLayoutInflater();
View row = inflater.inflate(R.layout.spinner_layout, parent, false);
TextView label = (TextView) row.findViewById(R.id.spinner_textview);
label.setText(getItem(position));
return row;
}
}
和布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:background="@drawable/transparent"
android:id="@+id/spinner_linear_layout">
<TextView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_gravity="center"
android:textSize="21sp"
android:singleLine="true"
android:id="@+id/spinner_textview"
android:textColor="@color/black" />
</LinearLayout>
(但它只是一个样本,如果你要根据不同的选择来调整,你可以在每个对象上添加一个布尔mSelected和更改视图依赖于这个布尔)
(But it's just an sample, if you want to resize depending on the selection, you can add a boolean mSelected on each object and change the view depending on this boolean)
编辑:然后在MultiSpinner:
Edit : Then in the MultiSpinner :
删除这样的:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
android.R.layout.simple_spinner_item,
new String[] { spinnerText });
setAdapter(adapter);
和微调添加新的自定义适配器:
and add the new custom adapter in the spinner :
MultiSpinner mMultiSpinner = (MultiSpinner) findViewById(R.id.multispinner);
mMultiSpinner.setAdapter(mCustomArrayAdapter);
这篇关于如何重新大小的项目在微调与选择题的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!