How to align the image and the text exactly equal when using in gridview android?

advertisements

Hi I am using Gridview to display images with text below by using custom adapter. But problem is when I fetch image and display, align gets changing and it's not proper.Here is my code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
    android:id="@+id/gridview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:stretchMode="columnWidth"
    android:numColumns="3" />
   </RelativeLayout>

gridview.row:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
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"
android:orientation="vertical" >
 <RelativeLayout
 android:id="@+id/RelativeLayout1"
 android:layout_width="match_parent"
  android:layout_height="wrap_content">
<ImageView
android:id="@+id/brand_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>

<TextView
android:id="@+id/brand_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/brand_picture"
android:gravity="center_vertical"
android:text="TextView"
 android:background="@color/blue"
 android:textColor="#FFFFFF" />

How to achieve the expected output with same image size and text below that.

Expected output is:

But my output looks like this.

Thanks.


try this..hope it works for u..

 <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/brand_picture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignRight="@+id/brand_name"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/brand_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/brand_picture"
            android:background="@color/blue"
            android:gravity="center_vertical"
            android:text="TextView"
            android:textColor="#ffffff" />