gpt4 book ai didi

android - 约束布局 : place TextView below ImageView

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:19 27 4
gpt4 key购买 nike

我面临着一个看似简单的布局任务:

  • 一个 ImageView 根据图像的宽高比获取完整的宽度和高度
  • 一个 TextView 在它下面

这是我的

<?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="wrap_content">

<ImageView
android:id="@+id/image_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/hamster"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText "
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/image_view"/>

</android.support.constraint.ConstraintLayout>

这就是它的样子:

enter image description here

如您所见,ImageView 顶部有一个边距,这是我不想要的。

如果我从

更改 ImageView 的 约束
        app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"

        app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"

(移除底部约束),结果如下所示:

enter image description here

现在 ImageView 位于我布局的最顶部,但是 TextView 已经消失了。请注意,对于第二个变体,Android Studio 3 的布局预览显示的布局与我想要的完全一样:

enter image description here

我做错了什么,我该如何解决?

注意:布局必须是ConstraintLayout,布局的高度必须是wrap_content

你可以找到我的测试项目here .

编辑:问题似乎只发生在较大的设备上。我正在使用 Nexus 9 模拟器。

最佳答案

是的,正如 Akash Amin 所说,在您的 ImageView 中添加这两行

    app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0"

关于android - 约束布局 : place TextView below ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47179017/

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