【发布时间】:2018-09-06 17:40:58
【问题描述】:
我正在以编程方式隐藏和显示一个文本视图。父约束布局已设置高度“wrap_content”。
但这里的问题是,如果最初隐藏 textview,即使我将 textview 可见性设置为 VISIBLE,ConstraintLayout titleLayout 也会保持折叠状态并且不显示子 textview。
将 ConstraintLayout 的高度设置为 wrap_content 很重要,这样布局可以根据 textview 内容进行增长/缩小。
<android.support.constraint.ConstraintLayout
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/descriLayout"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@id/titleLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="5dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/box_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="TextView"
android:textSize="12sp"
android:maxLines="5"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
layout.xml 的完整 xml 代码在这里会更有帮助。
-
Linear Layout 帮了我...我用 LinearLayout 更改了 constraintLayout,并按预期工作。
标签: android android-layout android-constraintlayout