gpt4 book ai didi

android - Android 上的 Cardview 大小

转载 作者:行者123 更新时间:2023-11-29 20:18:00 25 4
gpt4 key购买 nike

所以我想做的是在每张卡片中有一个带有图像的回收站 View 。

我如何知道每张卡片的宽度,以便我可以将图像以准确的尺寸传递给适配器并占用卡片的整个空间? (我希望所有图片都具有相同的大小。)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">


<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:id="@+id/phone_card_imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>


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

这是我在 cardview 上的代码。

最佳答案

为您的 ImageViewlayout_widthlayout_height 更改为固定的 dp 大小,这样就可以了。请注意,您也可以只固定高度,而宽度将是屏幕的宽度。

关于android - Android 上的 Cardview 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33586856/

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