XML微调框属性textAlignment =“right”API 16
问题描述:
我想设置属性到我的android应用程序的微调框和textAlignment = "right"
属性之一(问题是我有一个微调框,layout_width="match_parent"
所以有很多空间和我想要它在右边),但这只支持在API 17以上,而我想为API 16做一个应用程序 - 是否有解决方法?XML微调框属性textAlignment =“right”API 16
我的属性是:
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textAlignment="gravity"
android:id="@+id/MainSpinner"
tools:listitem="@layout/support_simple_spinner_dropdown_item"/>
目前的LinearLayout看起来是这样的:
而且我希望它看起来像这样:
在哪里:
答
这ANS的工作对我来说...
<Spinner
android:id="@+id/example_spinner"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textAlignment="right"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="2dp"
android:paddingBottom="2dp" />
我已经按照这样的:http://nevescheng.blogspot.fr/2013/05/spinner-with-item-text-aligned-to-center.html &这个工作得很好...
答
您可以创建这样一个适配器:
SpinnerAdapter spinnerAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, new String[]{"tata", "toto", "titi"});
spriner.setAdapter(spinnerAdapter);
并在您的布局中(res/layout/spinner_item.xml
):
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical|end"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />
答
Heyy Jeremy,尝试在你的微调器中添加android:textDirection="rtl"
属性。这个属性将给文本一个从右到左的方向。
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textAlignment="gravity"
android:textDirection="rtl"
android:id="@+id/MainSpinner"
tools:listitem="@layout/support_simple_spinner_dropdown_item"/>
请发表您的布局代码 – abhishesh