gpt4 book ai didi

android - 回收器 View 项中 View 之间的空白

转载 作者:行者123 更新时间:2023-11-29 17:30:07 26 4
gpt4 key购买 nike

我在回收站 View 中为每个项目使用卡片 View ,但我在图片下方和上方有空白,我不确定如何,我需要摆脱它。这是每个项目的 xml 布局。

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cv_custom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:clickable="true"
android:elevation="2dp"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="1dp"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:id="@+id/image_path"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/event_image" />

<TextView
android:id="@+id/custom_event_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="marquee"
android:gravity="start|top"
android:maxLines="1"
android:padding="5dp"
android:textColor="@color/parent"
android:textSize="20sp"
android:textStyle="bold" />

</LinearLayout>
</android.support.v7.widget.CardView>

这是我提供的 xml 当前的样子。一个项目有图像,一个没有图像。将回收器 View 的背景设置为红色,以便间隙更明显。

Sample

最佳答案

ImageView 中,您需要提供比例尺

android:scaleType="centerCrop"

您看到空白的原因是图像和容器的纵横比不同。

想象一下,您正试图将一个宽矩形放入一个正方形中。您可以将其放入,但顶部和底部将是“空的”或在本例中为白色。

如果您进行中心裁剪,则图像将被裁剪。这会将矩形切割成正方形,因此非常适合!

关于android - 回收器 View 项中 View 之间的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33320801/

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