当我从 Constraint 布局中删除所有 View 时,我希望它具有 0dp 高度(听起来像 wrap_content)但它会尽可能地拉伸(stretch)。
有记录的方法吗?我的意思是除了将 maxHeight 设置为 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>
最佳答案
我找不到合适的解决方案。
我想出的最简单的解决方法是添加一个带有 height=0
的额外 View 并且永远不要删除它:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="@+id/somethingWithNoHeight"
android:layout_width="match_parent"
android:layout_height="0dp" />
<!--<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lorem ipsum" />-->
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
我认为您应该填写一个错误以确保开发人员知道此类问题
关于android - 从最大拉伸(stretch)中停止空 ConstraintLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53363229/