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看起来是这样的:

enter image description here

而且我希望它看起来像这样:

enter image description here

在哪里:

的LinearLayout(水平)= enter image description here

的RelativeLayout = enter image description here

的TextView = enter image description here

的LinearLayout(垂直)= enter image description here

微调= enter image description here

按钮= enter image description here

+0

请发表您的布局代码 – abhishesh

这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 &这个工作得很好...

+0

我觉得上面的属性,为你工作的原因是因为'的android:layout_width =“WRAP_CONTENT”'线 - 矿母 – Jeremy

+0

匹配你可以上传你和要求的布局截图... –

+0

完成 - 这是一个微小的差异,我可能只需要在API 16中生活 – Jeremy

您可以创建这样一个适配器:

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"/>