使微调器文本正确对齐
Make Spinner Text Align Properly
我正在尝试使 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>
最近代码的结果:
如您所见,当我 select 任何状态时,它都会转到 Spinner 的左侧。我想与非 selected 字段进行类似对齐。
如果您在自定义布局中使用 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" />
如果您需要更多帮助,请告诉我。
我正在尝试使 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>
最近代码的结果:
如您所见,当我 select 任何状态时,它都会转到 Spinner 的左侧。我想与非 selected 字段进行类似对齐。
如果您在自定义布局中使用 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" />
如果您需要更多帮助,请告诉我。