Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将视图置于ConstraintLayout中另一个视图的右侧_Android_Android Constraintlayout - Fatal编程技术网

Android 将视图置于ConstraintLayout中另一个视图的右侧

Android 将视图置于ConstraintLayout中另一个视图的右侧,android,android-constraintlayout,Android,Android Constraintlayout,我希望textfield3位于textfield2的左侧 app:layout\u constraintRight\u toLeftOf=“@id/txt2”不起作用。 或者我错过了什么 layout.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/an

我希望textfield3位于textfield2的左侧

app:layout\u constraintRight\u toLeftOf=“@id/txt2”不起作用。 或者我错过了什么

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <TextView
        android:id="@+id/txt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/darker_gray"
        android:layout_margin="10dp"
        android:text="TEXTFIELD 1"/>

    <TextView
        android:id="@+id/txt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/txt1"
        app:layout_constraintEnd_toEndOf="parent"

        android:background="@android:color/holo_orange_dark"
        android:layout_margin="10dp"
        android:text="TEXTFIELD 2"/>

    <TextView
        android:id="@+id/txt3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/txt1"
        app:layout_constraintRight_toLeftOf="@id/txt2"
        android:background="@android:color/holo_red_light"
        android:layout_margin="10dp"
        android:text="TEXTFIELD 3"/>

</android.support.constraint.ConstraintLayout>


ConstraintLayout
中,每个小部件必须水平和垂直约束。如果不是,那么结果将是关闭的。某些
TextView
s缺少约束。请尝试以下操作:

<android.support.constraint.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/txt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="24dp"
        android:background="@android:color/darker_gray"
        android:text="TEXTFIELD 1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/txt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:background="@android:color/holo_orange_dark"
        android:text="TEXTFIELD 2"
        app:layout_constraintStart_toEndOf="@+id/txt3"
        app:layout_constraintTop_toTopOf="@+id/txt3" />

    <TextView
        android:id="@+id/txt3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:background="@android:color/holo_red_light"
        android:text="TEXTFIELD 3"
        app:layout_constraintStart_toStartOf="@+id/txt1"
        app:layout_constraintTop_toBottomOf="@+id/txt1" />

</android.support.constraint.ConstraintLayout>

实际上我的布局是正确的,我发布的屏幕截图来自Android Studio 3.0的布局编辑器。但是当我在模拟器上运行时,text3实际上是粘在text2的左边


这一定是版面编辑器中的一个错误。

考虑到您发布的屏幕截图,您想将
txt3
移动到
txt2
的左边缘旁边,还是想将
txt2
移动到
txt3
的右边缘旁边?txt3移动到txt2的左边缘旁边