constraintlayout视图在迁移到androidX后跳到右侧

constraintlayout视图在迁移到androidX后跳到右侧,android,Android,在此constraintlayout中,我无法使文本视图向左对齐 我有一件奇怪的事情,无论我做什么,TextView都会跳到右边 这是一张照片: 我刚迁移到androidX也许这是因为这个dunno 以下是xml布局位置建议 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android

在此
constraintlayout
中,我无法使文本视图向左对齐

我有一件奇怪的事情,无论我做什么,
TextView
都会跳到右边

这是一张照片:

我刚迁移到androidX也许这是因为这个dunno

以下是xml布局位置建议

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="wrap_content">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/pref_category_remote_battery_title"
        android:textAppearance="?android:attr/textAppearanceListItem"
        android:textColor="@color/default_400"
        app:layout_constraintStart_toStartOf="parent" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="8dp"
        android:text="@string/pref_category_remote_battery_switch_summ"

        android:textAppearance="?android:attr/textAppearanceSmall"
        app:layout_constraintStart_toStartOf="parent"
        tools:layout_editor_absoluteY="30dp" />

    <androidx.appcompat.widget.SwitchCompat
        android:id="@+id/switch_compat"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="24dp"
        android:layout_marginBottom="8dp"
        android:checked="false"
        android:textOff="OFF"
        android:textOn="ON"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/guideline3"
        app:layout_constraintTop_toTopOf="parent"
        app:showText="true" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.74722224" />

</androidx.constraintlayout.widget.ConstraintLayout>

如果你想让它留在左边,你可以像这样在你的布局中添加
android:layoutDirection=“ltr”

<?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"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layoutDirection="ltr">

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="pref_category_remote_battery_title"
    android:textAppearance="?android:attr/textAppearanceListItem"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="8dp"
    android:text="pref_category_remote_battery_switch_summ"
    android:textAppearance="?android:attr/textAppearanceSmall"
    app:layout_constraintEnd_toStartOf="@+id/guideline3"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/switch_compat"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="24dp"
    android:layout_marginBottom="8dp"
    android:checked="false"
    android:textOff="OFF"
    android:textOn="ON"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="@+id/guideline3"
    app:layout_constraintTop_toTopOf="parent"
    app:showText="true" />

 <android.support.constraint.Guideline
    android:id="@+id/guideline3"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="0.74722224" /> 

</android.support.constraint.ConstraintLayout>


为什么不试试下面的(文本视图2)呢



您是否使用了我发布的确切布局?你在哪部手机上测试呢谢谢你使用android.support.constraint.ConstraintLayout我使用androidx.ConstraintLayout.widget.ConstraintLayout。我不想降级哦,是的,我忘了提到我用于示例的项目使用的是支持版本,而不是androidX。您可以将版本更改为androidX并使用布局。可能会对您在使用字符串资源时发生的奇怪事情提出一个新问题。整个焦点都集中在这个问题上,你可以得到更多的关注。如果我的回答有帮助,请接受它,这样其他有相同问题的开发人员将来也可以使用它。请随时通过my与我联系,我会在我回家时尝试帮助您。谢谢没有工作,此布局是为自定义
androidx.preference.preference
而设计的,正如您在图片中看到的,不知道这可能很重要
<?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"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layoutDirection="ltr">

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="pref_category_remote_battery_title"
    android:textAppearance="?android:attr/textAppearanceListItem"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="8dp"
    android:text="pref_category_remote_battery_switch_summ"
    android:textAppearance="?android:attr/textAppearanceSmall"
    app:layout_constraintEnd_toStartOf="@+id/guideline3"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/switch_compat"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="24dp"
    android:layout_marginBottom="8dp"
    android:checked="false"
    android:textOff="OFF"
    android:textOn="ON"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="@+id/guideline3"
    app:layout_constraintTop_toTopOf="parent"
    app:showText="true" />

 <android.support.constraint.Guideline
    android:id="@+id/guideline3"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="0.74722224" /> 

</android.support.constraint.ConstraintLayout>
<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="8dp"
    android:text="@string/pref_category_remote_battery_switch_summ"
    android:textAppearance="?android:attr/textAppearanceSmall"
    app:layout_constraintStart_toStartOf="parent"
    tools:layout_editor_absoluteY="30dp"

    app:layout_constraintTop_toBottomOf="@id/textView"
    app:layout_constraintEnd_toStartOf="@id/switch_compat"/>