gpt4 book ai didi

Android:约束布局 - 比例调整后无法调整 ImageView 的 View 边界

转载 作者:太空狗 更新时间:2023-10-29 14:44:06 25 4
gpt4 key购买 nike

我正在使用 ConstraintLayout。

我有一个 ImageView ,我希望它是 16:9。在这个 ImageView 下方,我试图放置一个 TextView 。

现在,当 ImageView 设置为消失时,预计 TextView 会向上移动。但这没有发生。

有人可以尝试找出我的 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>

最佳答案

我认为您看到的行为是 ConstraintLayout 中设计的。 gone View 似乎应该占用任何空间,这似乎违反直觉,但在 this issue 的评论 #8 中在问题跟踪器上发表了以下声明:

@herrbert74 no, tadej is correct -- this is indeed a bug. In this example where the view is constrained on all sides and goes to gone, it should resolves to a point -- but constraints should still be respected. Meaning, in this case it should be at the center of all the constraints. Currently, the widget only set its size to zero, which works on single constraints, but doesn't on dual constraints. Beta 5 will have the correct behavior.

如果我理解正确,当 Viewgone 并且它像你的那样被限制在顶部和底部时,View 缩小为零(一个点),但仍然遵守其约束条件。换句话说,View 成为布局中心附近的一个点。您的 TextView 对 ImageView 的底部有一个顶部约束,它占用零空间,但零空间位于布局的中间。

所以,这并没有真正帮助,但它确实解释了正在发生的事情。

做你想做的事情的一种方法是在你制作 ImageView gone 时删除 ImageView 的底部约束.如果没有 bottom 约束,ImageView 将 float 到布局的顶部并带走 TextView

关于Android:约束布局 - 比例调整后无法调整 ImageView 的 View 边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42757258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com