I am trying to create a grid layout of cards similar to what is used in google play like this
The layout i am using and the layout obtained are these:
For 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>
for 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>
The output that I get is this:
The image size that i am using is 356x500. (I do get a somewhat well sized grid on using 300x300) The issues that i am facing are:
- 1.As this image shows, the cards are too big with lots of white spaces around the image and the image does not fit like in the google play store. How do i make the card be propotional to the image. The amount of white space changes with change in image size.
- The card is "stuck" to the left edge of the screen . How do i keep spacing between the edge of the screen and the card.
Please help me in rectifying this issue. Thanks