Question

I have fragment with a view like this

enter image description here

Inside this grid layout my item must be arranged like this

enter image description here

you can see the items have different heights . even the space between each rows are different .I try to achieve this through giving row spans . but all my logic gone wrong

I refer these links : Link 1 ,Link 2, Link 3

But my ideas are not helping me . can anyone suggest me how to achieve this

EDIT :After accepting the answer

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.35">

</LinearLayout>

<GridLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:rowCount="20"
    android:columnCount="1">

    <LinearLayout
        android:layout_row="0"
        android:layout_gravity="fill">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="Name"
            android:gravity="left"
            android:layout_weight="1"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="EditText"
            android:gravity="center"
            android:layout_weight="1"/>
        <Space 
            android:layout_width="45dp"
            android:layout_height="match_parent"/>
    </LinearLayout>
    <Space
        android:layout_row="1"
        android:layout_gravity="fill"
        android:layout_rowSpan="1"/>
    <LinearLayout
        android:layout_row="3"
        android:layout_gravity="fill"
        android:layout_rowSpan="4">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="Address"
            android:gravity="left"
            android:layout_weight="1"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:lines="4"
            android:text="EditText"
            android:gravity="center"
            android:layout_weight="1"
           />

        <Space 
            android:layout_width="45dp"
            android:layout_height="match_parent"/>
    </LinearLayout>
    <Space
        android:layout_row="7"
        android:layout_gravity="fill"/>
    <LinearLayout
        android:layout_row="8"
        android:layout_gravity="fill">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="Email"
            android:gravity="left"
            android:layout_weight="1"/>


        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="EditText"
            android:gravity="center"
            android:layout_weight="1"/>
        <ImageView android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingLeft="30dp"
            android:src="@android:drawable/arrow_up_float"/>

    </LinearLayout>
    <Space
        android:layout_row="9"
        android:layout_gravity="fill"/>
    <LinearLayout
        android:layout_row="10"
        android:layout_gravity="fill"
        android:layout_rowSpan="6">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="About Me"
            android:gravity="left"
            android:layout_weight="1"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:lines="5"
            android:text="EditText"
            android:gravity="center"
            android:layout_weight="1"/>
        <Space 
            android:layout_width="45dp"
            android:layout_height="match_parent"/>
    </LinearLayout>
    <Space
        android:layout_row="16"
        android:layout_gravity="fill"
        android:layout_rowSpan="3"/>
    <LinearLayout
        android:layout_row="19"
        android:layout_gravity="fill">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="Nick Name"
            android:gravity="left"
            android:layout_weight="1"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="EditText"
            android:gravity="center"
            android:layout_weight="1"/>
      <ImageView android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingLeft="30dp"
            android:src="@android:drawable/arrow_up_float"/>
    </LinearLayout>

</GridLayout>

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.30">

</LinearLayout>

Was it helpful?

Solution

// Try this way,hope this will help solve your problem...

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.35">

    </LinearLayout>

    <GridLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:rowCount="20"
        android:columnCount="1">

        <LinearLayout
            android:layout_row="0"
            android:layout_gravity="fill">
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="Name"
                android:gravity="left"
                android:layout_weight="1"/>

            <EditText
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="EditText"
                android:gravity="center"
                android:layout_weight="1"/>
        </LinearLayout>
        <Space
            android:layout_row="1"
            android:layout_gravity="fill"
            android:layout_rowSpan="1"/>
        <LinearLayout
            android:layout_row="3"
            android:layout_gravity="fill"
            android:layout_rowSpan="4">
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="Address"
                android:gravity="left"
                android:layout_weight="1"/>

            <EditText
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:lines="4"
                android:text="EditText"
                android:gravity="center"
                android:layout_weight="1"/>
        </LinearLayout>
        <Space
            android:layout_row="7"
            android:layout_gravity="fill"/>
        <LinearLayout
            android:layout_row="8"
            android:layout_gravity="fill">
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="Email"
                android:gravity="left"
                android:layout_weight="1"/>

            <EditText
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="EditText"
                android:gravity="center"
                android:layout_weight="1"/>
        </LinearLayout>
        <Space
            android:layout_row="9"
            android:layout_gravity="fill"/>
        <LinearLayout
            android:layout_row="10"
            android:layout_gravity="fill"
            android:layout_rowSpan="6">
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="About Me"
                android:gravity="left"
                android:layout_weight="1"/>

            <EditText
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:lines="5"
                android:text="EditText"
                android:gravity="center"
                android:layout_weight="1"/>
        </LinearLayout>
        <Space
            android:layout_row="16"
            android:layout_gravity="fill"
            android:layout_rowSpan="3"/>
        <LinearLayout
            android:layout_row="19"
            android:layout_gravity="fill">
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="Nick Name"
                android:gravity="left"
                android:layout_weight="1"/>

            <EditText
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="EditText"
                android:gravity="center"
                android:layout_weight="1"/>
        </LinearLayout>

    </GridLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.30">

    </LinearLayout>

</LinearLayout>

OTHER TIPS

//you need to do with wieghtsum

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="20dp"
    android:orientation="horizontal"

    android:weightSum="125" >

    <View
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="35" />

    <GridLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="65" />

    <View
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="30" />

</LinearLayout>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top