Android 上的 Cardview 大小
Cardview size on Android
所以我想做的是在每张卡片中包含图片的回收站视图。
我怎样才能知道每张卡片的宽度,以便我可以将图像以准确的尺寸传递给适配器并获取卡片的整个 space? (我希望所有图片都具有相同的大小。)
<?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 上的代码。
为您的 ImageView
将 layout_width
和 layout_height
更改为 dp 中的固定大小,这样就可以了。
请注意,您也可以只固定高度,宽度将是屏幕的宽度。
所以我想做的是在每张卡片中包含图片的回收站视图。
我怎样才能知道每张卡片的宽度,以便我可以将图像以准确的尺寸传递给适配器并获取卡片的整个 space? (我希望所有图片都具有相同的大小。)
<?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 上的代码。
为您的 ImageView
将 layout_width
和 layout_height
更改为 dp 中的固定大小,这样就可以了。
请注意,您也可以只固定高度,宽度将是屏幕的宽度。