android - 使微调器文本正确对齐
问题描述
我正在尝试使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 的左侧。我想与非选定字段进行类似的对齐。
解决方案
如果您在自定义布局中使用 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" />
如果您需要更多帮助,请告诉我。
推荐阅读
- composer-php - 无法使用 composer 2.0 在 Drupal 8.9.6 上安装/更新模块
- c# - 错误 MSB1003:指定项目或解决方案文件。使用 azure 构建管道但找不到 csproj 文件
- tcp - ESXI 6.7 上的 TCP 连接重置
- sql - 我可以将最新更新的行放在顶部吗
- javascript - Sequelize:仅选择用户所在的聊天
- java - Mapbox 导航崩溃
- ios - 将 API 调用返回到 JSON 时出现 valueNotFound 错误
- node.js - 如何通过 Docker 集成容器化的 Web 组件(React)?
- javascript - 如何使用 event.target 在元素之间切换类?
- terraform - 在 Terraform 中隐藏秘密