垂直拉伸ImageView在ConstraintLayout中的约束

3

我在让ImageView垂直填充剩余空间方面遇到了一些问题。 我在截图上用红色标出了它。 有人可以看一下并提供一些建议吗?

https://istack.dev59.com/PBio1.webp

这是关联的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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.happybirthday.MainActivity">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:contentDescription="@string/happy_birthday_toyou"
    android:scaleType="centerCrop"
    android:src="@drawable/invite"
    app:layout_constraintBottom_toTopOf="@+id/textViewBottom"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textViewTop" />

<TextView
    android:id="@+id/textViewTop"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:padding="8dp"
    android:fontFamily="sans-serif"
    android:text="@string/happy_birthday_toyou"
    android:textColor="@color/colorWhite"
    android:background="@color/colorBlack"
    android:textSize="@dimen/text_size"
    android:gravity="start"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintStart_toStartOf="parent"
   />

<TextView
    android:id="@+id/textViewBottom"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="@color/colorBlack"
    android:fontFamily="sans-serif"
    android:gravity="end"
    android:padding="8dp"
    android:text="@string/from_me"
    android:textColor="@color/colorWhite"
    android:textSize="@dimen/text_size"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    />



</android.support.constraint.ConstraintLayout>
1个回答

5
尝试将您的imageView中的“android:layout_height =“wrap_content”更改为0dp。

1
我发誓昨天我试过了,但它不起作用。刚刚尝试了一下,现在它可以正常工作 :) - davemib123
Android就像一个充满魔力的世界。记得要使用适当的约束条件,因为在试图让你的视图填充布局时,它们可能会有些棘手。 - Jan Stoltman
爱你宝贝 xx - bharv14

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接