2016-09-28 89 views
8

我想設置屬性到我的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

回答

3

這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

1

您可以創建這樣一個適配器:

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

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