0

I am looking to obtain a layout like this:

enter image description here

I am trying to create a gridview item like the one used here for 'albums', but i am trying for a simpler version with just an image on top and text below it. Here is my XML code:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<RelativeLayout 
    android:id="@+id/relativelayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg_card"
     >

    <ImageView
        android:id="@+id/imgIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />

    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imgIcon"
        android:layout_alignTop="@+id/imgIcon"
        android:layout_alignRight="@+id/imgIcon"
        android:layout_alignBottom="@+id/imgIcon"
        android:layout_margin="1dp"
        android:gravity="center"
        android:textColor="#000000" />

</RelativeLayout></FrameLayout>

Howver, when i do this, i get an image in the centre with with white spaces all around it and no text displayed. What is the correct layout to be used to obtain a griditem like shown in the image Thanks

Shivam Bhalla
  • 1,879
  • 5
  • 35
  • 63

1 Answers1

0

You can try this code

<?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">

<ImageView
    android:id="@+id/imgIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/picture"
     />

<TextView
    android:id="@+id/txtTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/imgIcon"
    android:layout_margin="1dp"
    android:textColor="#000000"
    android:text="testing" 
    android:layout_centerInParent="true"/>

Tünde
  • 885
  • 4
  • 11
  • 24