我正在使用ConstraintLayout。
我有一个想要16:9的图像视图。在此图像视图下方,我正在尝试放置文本视图。
现在,当图像视图设置为消失时,预计文本视图会向上移动。但这没有发生。
有人可以尝试在我的XML布局中找出问题:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/dark_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="15dp"
tools:layout_width="300dp"
tools:layout_height="300dp"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/logo"
app:layout_constraintDimensionRatio="W,16:9"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/image"
android:ellipsize="marquee"
android:maxLines="4"
android:textSize="28sp"
android:textColor="#000000"
android:text="The is the test that does not seem to work"
android:layout_marginTop="12.41dp"
app:layout_goneMarginTop="0dp"/>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:0)
我认为您所看到的行为是ConstraintLayout
所设计的行为。似乎反直觉的是,gone
视图似乎占用了任何空间,但在this issue的评论#8中,问题跟踪器上发表了这样的声明:
@ herrbert74不,tadej是正确的 - 这确实是一个错误。在这个视图被限制在所有方面并且消失的示例中,它应该解析为一个点 - 但是仍然应该遵守约束。意思是,在这种情况下,它应该是所有约束的中心。目前,窗口小部件仅将其大小设置为零,这适用于单个约束,但不适用于双约束。 Beta 5将具有正确的行为。
如果我理解正确的话,当View
成为gone
并且它被限制在顶部和底部时,就像你的那样,那么View
会缩小为零(a点)但其约束仍然受到尊重。换句话说,View
成为布局中心附近的点。您的文本视图在ImageView
的底部有一个顶部约束,它占用零空间,但零空间位于布局的中间。
所以,这并没有什么帮助,但它确实解释了发生了什么。
执行您要执行的操作的一种方法是在ImageView
ImageView
时删除gone
上的底部约束。如果没有底部约束,ImageView
将浮动到布局的顶部并随身携带TextView
。