I am trying to achieve this view:
This is the partial view , I can have view vertically merged with 2 cells or horizontally merged 2 cells or single small view.
This view can scroll vertically
Please help me to get this.
I am trying to achieve this view:
This is the partial view , I can have view vertically merged with 2 cells or horizontally merged 2 cells or single small view.
This view can scroll vertically
Please help me to get this.
You can create this layout by using nested LinearLayout
with attribute layout_weight
and weightSum
. To make this layout scrollable
, use ScrollView
as a root layout.
Here is an working example:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical">
<!-- ROW1 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#ff0000">
</LinearLayout>
<!-- ROW2 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- ROW2 COL1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:background="#00ff00">
</LinearLayout>
<!-- ROW2 COL2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:orientation="vertical"
android:layout_weight="1"
android:weightSum="2">
<!-- ROW2 COL2 CHILD1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_marginBottom="4dp"
android:layout_weight="1"
android:background="#0000ff">
</LinearLayout>
<!-- ROW2 COL2 CHILD2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="#0000ff">
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!-- ROW3 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- ROW3 COL1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:background="#fff000">
</LinearLayout>
<!-- ROW3 COL2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:background="#fff000">
</LinearLayout>
</LinearLayout>
<!-- ROW4 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- ROW4 COL1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:background="#ff00ff">
</LinearLayout>
<!-- ROW4 COL2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:orientation="vertical"
android:layout_weight="1"
android:weightSum="2">
<!-- ROW4 COL2 CHILD1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_marginBottom="4dp"
android:layout_weight="1"
android:background="#00ffff">
</LinearLayout>
<!-- ROW4 COL2 CHILD2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="#00ffff">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
OUTPUT:
You can also use GridLayout
to achieve this view.
Here is a good tutorial about GridLayout
and some stackOverflow answers.
Hope this will help~