首页 > 解决方案 > 无线电组文本在 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>

注意

标签: androidandroid-layout

解决方案


 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"

推荐阅读