我正在尝试创建类似于 google play 中使用的卡片网格布局,如下所示
我正在使用的布局和获得的布局是:
对于 GridView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#e5e5e5"
>
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="60dp"
android:numColumns="2"
android:layout_marginLeft="2dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</RelativeLayout>
对于 GridItem:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_card"
>
<ImageView
android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:textSize="17sp"
android:layout_below="@id/imgIcon"
android:layout_marginTop="35dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
我得到的输出是这样的:
我使用的图像尺寸是 356x500。(我在使用 300x300 时确实得到了一个大小合适的网格)我面临的问题是:
- 1.如图所示,卡片太大,图像周围有很多空白,图像不适合 google play 商店。我如何使卡片与图像成比例。空白的数量随着图像大小的变化而变化。
- 卡片“卡”在屏幕的左边缘。我如何保持屏幕边缘和卡片之间的间距。
请帮助我纠正这个问题。谢谢