【发布时间】:2021-04-07 12:52:00
【问题描述】:
我使用下面的 XML 来使用占位符。
但使用占位符时我只能看到button1、'root_container3'。
'root_container2' 不是占位符,因为 MATCH_CONSTRAINT
android:id="@+id/button2"
android:layout_width="0dp" // MATCH_CONSTRAINT
android:layout_height="0dp" // MATCH_CONSTRAINT
我猜button2 不是用match_constraint 衡量的
(如果按钮具有特定的维度值,例如button3,它可以工作,但 Match_constraint 没有。)
我不知道这个..
<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:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/activity_main_scene"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.Placeholder
android:id="@+id/place_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/root_container2"
android:layout_width="200dp"
android:layout_height="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Button2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/root_container3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent">
<Button
android:id="@+id/button3"
android:layout_width="200dp"
android:layout_height="100dp"
android:text="Button3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
/
button1.setOnClickListener {
place_holder.setContentId(R.id.button1)
}
button2.setOnClickListener {
place_holder.setContentId(R.id.root_container2)
}
button3.setOnClickListener {
place_holder.setContentId(R.id.root_container3)
}
【问题讨论】:
-
您能否添加建议的屏幕设计以提高清晰度
标签: android android-constraintlayout placeholder