当我从我的约束布局中删除所有视图时,我希望它的高度为0dp(类似于wrap_content),但它会尽可能地拉伸。
有没有文档记录的方法可以做到这一点?我的意思是除了设置最大高度为0
或隐藏它之外。
我已经尝试过使用app:layout_constrainedHeight="true"
和"wrap_content"
,但它不起作用。
<?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">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</android.support.constraint.ConstraintLayout>
onViewAdded
和onViewRemoved
以设置visibility=View.GONE
,如果它没有子项的话,这样自身就可以工作。由于您将ConstraintLayout用作根视图,因此在GONE视图上的约束仍应该起作用。 - Andrey Busik