Search code examples
androidlayoutgridview

ImageView on a GridView


I have a GridView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="5dp"
    android:layout_weight="1"
    android:orientation="horizontal" >
    <GridView
        android:id="@+id/gridView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/DarkSlateGray"
        android:layout_weight="1"
        android:columnWidth="200dp"
        android:gravity="center"
        android:numColumns="auto_fit"
        android:stretchMode="none" >
    </GridView></LinearLayout>

I want to add an ImageView on top of this.

Tried <include>:

<include layout="@layout/connection"/>  

connection.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl_connection"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <ImageView
        android:src="@drawable/globe_connected_icon_48"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" /></RelativeLayout>   

But result looks like this:

Grid2

Is there a way to show it on top of the GridView like this:

Grid3


Solution

  • Change the Linear Layout to a Relative Layout, then have both the grid view and the image view align to the top left of the parent. Make sure the the image view is below the grid view so that it appears on top.