首页 > 解决方案 > 使微调器文本正确对齐

问题描述

我正在尝试使SearchableSpinner文本对齐正确

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:layout_marginLeft="15dp"
            android:orientation="vertical">
            <com.toptoche.searchablespinnerlibrary.SearchableSpinner
                android:id="@+id/statespinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                app:hintText="Please Select your State"
                android:padding="4dp"
                android:layout_marginBottom="6dp"
                />
            <com.toptoche.searchablespinnerlibrary.SearchableSpinner
                android:id="@+id/districtspinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                app:hintText="Please Select your District"
                android:padding="4dp"
                android:layout_marginBottom="6dp" />
            <com.toptoche.searchablespinnerlibrary.SearchableSpinner
                android:id="@+id/assemblyspinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                app:hintText="Please Select your Assembly Constituency"
                android:layout_marginBottom="6dp"
                android:padding="4dp"
                />
            <com.toptoche.searchablespinnerlibrary.SearchableSpinner
                android:id="@+id/wardspinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                app:hintText="Please Select your Ward"
                android:layout_marginBottom="6dp"
                android:padding="4dp"
               />
</LinearLayout>

最近代码的结果:

结果

正如您所看到的,当我选择任何状态时,它会转到 Spinner 的左侧。我想与非选定字段进行类似的对齐。

标签: androidandroid-layoutandroid-spinner

解决方案


如果您在自定义布局中使用 TextView 在微调器中显示下拉项,则必须在该 TextView 中添加一些填充。

就像是:

spinner_item.xml

(以适用者为准)

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="25dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:background="#b3e2ff"
/>

或者

(四面都有填充)

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp" />

如果您需要更多帮助,请告诉我。


推荐阅读