android - 无线电组文本在 RTL 语言中奇怪地错位
问题描述
无线电组在我的手机上的行为很奇怪,文本完全未对齐,如下图所示,但奇怪的是它在 android studio 的 XML 布局可视化器中正确对齐
我手机上的图像未对齐
android studio中XML布局可视化器上的完美图像
布局的 XML 代码
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:mlns="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/_28dp_dp"
android:background="@drawable/bg_rounded_screen"
mlns:android="http://schemas.android.com/apk/res/android">
------
<TextView
android:id="@+id/textView"
style="@style/HintTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_36dp_dp"
android:text="@string/language"
app:layout_constraintBottom_toTopOf="@+id/tg_group_language"
app:layout_constraintStart_toStartOf="@+id/et_name"
app:layout_constraintTop_toBottomOf="@+id/et_phone" />
<RadioGroup
android:id="@+id/tg_group_language"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_30dp_dp"
android:orientation="horizontal"
android:gravity="end"
app:layout_constraintBottom_toTopOf="@+id/btn_save_changes"
app:layout_constraintEnd_toEndOf="@id/et_name"
app:layout_constraintStart_toStartOf="@id/et_name"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:singleSelection="true">
<RadioButton
android:id="@+id/radio_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/english" />
<RadioButton
android:id="@+id/radio_arabic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/عربي" />
</RadioGroup>
-----
</androidx.constraintlayout.widget.ConstraintLayout>
注意:
- 我没有以编程方式应用任何样式
- 当手机的语言是 RTL 时,它似乎工作正常,但是当手机是 LTR(英语)时,使用这个答案试图强制应用程序的语言为 RTL 时,它显示了这种错位
解决方案
app:layout_constraintEnd_toEndOf="@id/et_name"
app:layout_constraintStart_toStartOf="@id/et_name"
由于这两行,您会出现错位。如果您希望收音机组位于中心,请使用 parent 而不是 et_name。
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
推荐阅读
- docker - 在云中为 Redis 创建连接字符串
- mongodb - 在 mongo 4.4 中,位置投影不能与文字错误一起使用
- python - 我们可以只使用函数在 python 中创建一个测验并跟踪分数吗
- android - 自定义 android 11 更新
- python - 如果 NaN,Pandas 用以前的值替换当前值
- git - 使用 Azure DevOps REST API 更新 Git 存储库中的文件编码
- powerbi-desktop - 单击 PowerBI 中的列多维度量
- database - 我在本地(xampp)服务器中的 wordpress 站点现在显示“建立数据库连接时出错”
- domain-driven-design - 使用 DDD CQRS 时数据的完整性
- javascript - 我可以修补现有类以扩展另一个类吗?