このような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 ストアのように画像が収まりません。カードを画像に比例させるにはどうすればよいですか。画像サイズを変更すると余白の量が変わります。
- カードが画面の左端に「スタック」しています。画面の端とカードの間の間隔を保つ方法を教えてください。
この問題を修正するのを手伝ってください。ありがとう