android - 将数字与 RatingBar 对齐 - Android
问题描述
我在我的应用程序中使用 RatingBar 并为 Stars 分配数字以方便用户,但这些数字的对齐方式会随着设备的更改而改变。尽管我为不同的屏幕使用了不同的布局,但仍然在某些移动设备上格式不正确。
我想要的是
某些手机上显示的内容
解决方案
使用约束布局作为父级并适合线性布局。那应该可以正常工作。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="38dp"
tools:layout_editor_absoluteY="192dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/ratingBar"
app:layout_constraintEnd_toEndOf="@+id/ratingBar"
app:layout_constraintStart_toStartOf="@+id/ratingBar">
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="1"
android:textAlignment="center" />
<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="2"
android:textAlignment="center" />
<TextView
android:id="@+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="3"
android:textAlignment="center" />
<TextView
android:id="@+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="4"
android:textAlignment="center" />
<TextView
android:id="@+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="5"
android:textAlignment="center" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
推荐阅读
- python - Libeosa 在尝试读取音频文件时随机崩溃,尽管它在其他时候可以正常读取相同的文件
- angular - 收到父数据之前的角度子渲染
- arangodb - 在 arangosearch 视图中对同一查询中的不同字段使用不同的分析器
- wordpress - 在 Wordpress 插件上使用 REST API 进行用户注册
- python - 如何替换 Dataframe 列中的子字符串,但仅在字符串的开头?
- git - 恢复 Git 中已暂存但未提交的丢失文件
- asynchronous - 如何在干净的架构中设计一个存储库写入 pub/sub 并从数据库中读取
- python - 在 OSMNX ox.plot_graph_routes() 中更改图形大小
- r - 如何更改 R 中 reReg 包中 plotEvents 中线条的颜色?
- react-native-ios - 错误:预期节点是 ["Statement"] 类型,但得到了 "AssignmentExpression" | 反应原生 IOS