Am trying to place 4 image views and one textview above gridview and my layout should me like this(blue-textview, orange- imageview and next gridview)
and inbetween the gap is also essential.I searched but couldn't achieve my view. I referred here for my gridview layout. Help me in achieving this. Thanks in advance.
Asked
Active
Viewed 1,508 times
0

AndroidOptimist
- 1,419
- 3
- 23
- 38
-
Just use RelativeLayout to wrap the components you need, and specify their position separately. – reTs Sep 26 '13 at 05:30
-
can u please explain it with simple example – AndroidOptimist Sep 26 '13 at 05:31
-
@Alliswell read this http://www.mkyong.com/android/android-relativelayout-example/ – Metalhead1247 Sep 26 '13 at 05:33
2 Answers
0
// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="right">
<ImageView
android:layout_width="100dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginTop="10dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_launcher"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="textview"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginTop="10dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_launcher"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_launcher"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
</LinearLayout>
<GridView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:layout_weight="1">
</GridView>
</LinearLayout>

Haresh Chhelana
- 24,720
- 5
- 57
- 67
0
Try below code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/layoutHead"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imgOrange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="5dip"
android:background="@drawable/ic_launcher" />
</RelativeLayout>
<LinearLayout
android:id="@+id/linearmain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imgOrange"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imgOrange1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:background="@drawable/ic_launcher" />
<TextView
android:id="@+id/txtTemp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="test" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imgOrange"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imgOrange2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:background="@drawable/ic_launcher" />
<TextView
android:id="@+id/txtTemp1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="test" />
</LinearLayout>
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>

Pratik Dasa
- 7,439
- 4
- 30
- 44