'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:
Is there a way to show it on top of the GridView
like this:
Solution 1:[1]
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.
Solution 2:[2]
Change your LinearLayout
orientation to vertical and place the ImageView
above the GridView
code. For LinearLayout
you can provide attributes to define where in the layout a view will be, such attributes: gravity
and layout_gravity
. RelativeLayout
provides similar attributes: ex.layout_alignParentTop
. Also, use android:background="@null"
in your ImageView
if you want the white boarder around your image to be transparent.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | adonal3 |
Solution 2 |