我正在尝试在 Android 中对齐 Spinner 的选定文本。它应该与布局中其他 TextView 和 EditText 的匹配缩进对齐。
我的布局中有什么:
http://i.imgur.com/Y5sgbsN.png
我想做什么:
http://i.imgur.com/viVHpiC.png
我的布局代码:
<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"/>
请帮助我解决此 UI 更改。
谢谢
更新 1: 父布局代码:
<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" >
最佳答案
这是 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);
如果您不需要如下所示的自己的适配器,也可以使用 SimpleAdapter
ArrayAdapter<String> simpleadapter = new ArrayAdapter<String>(YourActivityName.this, R.layout.spinnerinflate, getResources().getStringArray(R.array.yourarray));
spinner.setAdapter(simpleadapter);
通过这个膨胀你可以做任何你想要的格式。如果有帮助,请告诉我。
关于java - Android微调器的选定文本对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24930816/