简体   繁体   中英

Selected text alignment for Android spinner

I am trying to align selected text of a Spinner in Android. It should align to the matching indentation of the other TextView and EditText in the layout.

What I have in my layout:

http://i.imgur.com/Y5sgbsN.png

What i want to do:

http://i.imgur.com/viVHpiC.png

My Layout code:

 <Spinner
        android:id="@+id/spinner1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/TextView01"
        android:layout_below="@+id/TextView01"
        android:entries="@array/bank_arrays"
        android:prompt="@string/bank_prompt"
        android:fontFamily="arial,helvetica"
        android:hint="@string/bank_prompt"
        android:spinnerMode="dialog"
        android:ellipsize = "none"/>

Please help me out with this UI change.

Thanks

Update 1: Parent Layout code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="14.5sp"
    android:layout_marginLeft="14.5sp"
    android:layout_marginRight="14.5sp"
    android:layout_marginTop="14.5sp"
    tools:context=".RegistrationActivity" >

This is the spinnerinflate.xml

<TextView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/spinnertext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:textColor="#00f5ff"
            android:textSize="@dimen/text_size"
 android:text="Text Here" >
    </TextView>

In your code you can set the custom Layout for spinner as 

MyAdapter myAdapter = new MyAdapter(this, R.layout.spinnerinflate, arraylist); spinner.setAdapter(myAdapter);


You can use SimpleAdapter as well if you don't need to have your own adapter as below

ArrayAdapter<String> simpleadapter = new ArrayAdapter<String>(YourActivityName.this, R.layout.spinnerinflate, getResources().getStringArray(R.array.yourarray));
spinner.setAdapter(simpleadapter);

By this inflate you can do whatever formatting you want. Please let me know if it helps.

you can use this lines

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:paddingLeft="0dp"
    android:textDirection="ltr" />

and you can increase padding from left to more space

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM