Android 将视图置于ConstraintLayout中另一个视图的右侧
我希望textfield3位于textfield2的左侧 app:layout\u constraintRight\u toLeftOf=“@id/txt2”不起作用。 或者我错过了什么 layout.xmlAndroid 将视图置于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
<?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的左边缘旁边