android - 从最大拉伸停止空的 ConstraintLayout
问题描述
当我从我的约束布局中删除所有视图时,我希望它的高度为 0dp(就像听起来的 wrap_content 一样),但它会尽可能地伸展。
有记录的方法吗?我的意思是除了将 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
并且永远不要删除它:
<?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>
我相信您应该填写一个错误以确保开发人员知道这样的问题
推荐阅读
- docker - 如何设置容器名称为计算机名称的容器?
- php - 如果 (is_page_template()) 在 header.php 中不起作用
- java - 您如何为跨包的多个存储库集中一个配置?
- python - 如何使用 Django 文件存储在 API 和 Worker 之间共享文件
- android - 如何实现将文本跟踪到语音,以便显示正在读取的行
- python - 如何将我的输入设置为 Python 中已经存在的变量?
- jquery - 在现有项目中实施引导选择
- node.js - 包含箭头函数捕获“this”的全局值
- php - 比较两个 DateTime 对象的 PHP 性能负载
- c# - 如何调试 UWP 应用的后台服务(IBackgroundTask)?