Java 你怎么会';您不想在约束布局中使用匹配父项吗?
我在网上读到的所有内容都说不要在约束视图中为高度和宽度属性使用match_parent,因为它无法使用,也无法工作。我已经在一些项目中使用了约束布局,现在我确实使用了match_parent,并且它确实有效。是否有一个更新,我没有注意到它现在可以在哪里使用?如果不是,为什么它在我的情况下有效,而对其他人似乎根本不起作用 示例代码:Java 你怎么会';您不想在约束布局中使用匹配父项吗?,java,android,Java,Android,我在网上读到的所有内容都说不要在约束视图中为高度和宽度属性使用match_parent,因为它无法使用,也无法工作。我已经在一些项目中使用了约束布局,现在我确实使用了match_parent,并且它确实有效。是否有一个更新,我没有注意到它现在可以在哪里使用?如果不是,为什么它在我的情况下有效,而对其他人似乎根本不起作用 示例代码: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.C
<?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"
android:background="#f9d1ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/preview"
android:layout_marginLeft="4dp"
android:text="Last Entry:"
android:textSize="12dp"
app:layout_constraintTop_toTopOf="@id/saveButton"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="@id/clearButton"
android:id="@+id/dataText"
android:textSize="16dp"
android:layout_marginLeft="8dp"
android:text=""
android:textStyle="bold"
/>
<Button
android:layout_width="75dp"
android:layout_height="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/clearButton"
android:id="@+id/saveButton"
android:text="Save"
android:textSize="12dp"
android:layout_margin="8dp"
android:background="@drawable/buttonscreen"
android:padding="6dp"/>
<Button
android:layout_width="75dp"
android:layout_height="30dp"
android:gravity="center"
android:padding="6dp"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
android:text="Clear All"
android:id="@+id/clearButton"
android:textSize="12dp"
app:layout_constraintTop_toBottomOf="@+id/saveButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/saveButton"
app:layout_constraintEnd_toEndOf="@id/saveButton"
android:background="@drawable/buttonscreen"/>
</androidx.constraintlayout.widget.ConstraintLayout>
尝试此约束,使哪个视图与父视图匹配
请尝试使用此约束,使哪个视图与父视图匹配这就是问题所在,我也使用这些约束,但在“高度”和“宽度”属性中也使用“匹配父视图”。由于我执行了您列出的约束,它是否忽略了这些约束?将布局高度和宽度设置为0dp。试试看,这样它就可以像我之前所做的那样工作了。我只是在研究约束布局,我读到的所有东西都说match_parent不应该起作用,但对我来说它确实起作用。我只是想知道为什么它在我的上下文中起作用。这就是问题所在,我也使用了这些约束,但在高度和宽度属性中也使用了match_parent。由于我执行了您列出的约束,它是否忽略了这些约束?将布局高度和宽度设置为0dp。试试看,这样它就可以像我之前所做的那样工作了。我只是在研究约束布局,我读到的所有东西都说match_parent不应该起作用,但对我来说它确实起作用。我只是想知道为什么它在我的环境中起作用。
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"