How to make Listview with tablerow

1.1k views Asked by At

i am new in android studio. currently i making listview, i want to make layout like this picture :

enter image description here

this is my code now

 <TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:weightSum="3">

        <TableLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.5">

            <TableRow

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:layout_marginLeft="10dp"
                >


                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="Type"
                    android:textSize="18dp"
                    android:fontFamily="sans-serif"
                    android:textColor="@color/black"
                    android:id="@+id/tvTipeRequest"
                    android:width="130dp" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                >

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="Date"
                    android:fontFamily="sans-serif"
                    android:id="@+id/tvTanggalRequest"
                    android:textSize="15dp"
                    android:width="130dp" />

            </TableRow>


        </TableLayout>

        <TextView
            android:layout_width="1dp"
            android:layout_weight="1"
            android:layout_height="50dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black"
            android:text="Status"
            android:textSize="15dp"
            android:gravity="end"
            android:paddingTop="10dp"
            android:fontFamily="sans-serif"
            android:layout_marginTop="15dp"
            android:id="@+id/tvStatus"
            android:layout_column="38" />

    </TableRow>

</TableLayout>

i realize that tablerow cant do the rowspan, so it didnt work out.

is there any simple way to do that?

2

There are 2 answers

0
Piyush On

Use this hierarchy:

 <LinearLayout
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:weightSum="1"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="0.2"
        android:orientation="vertical"
        android:layout_height="wrap_content">

        <!--ImageView here-->
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="0.8"
        android:orientation="vertical"
        android:layout_height="wrap_content">

        <!--All textViews here-->
    </LinearLayout>

</LinearLayout>
0
Devrim On

You can have a single relative layout as your view container. That would be more efficient.

Read.

Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/image_view"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="8dp"
        android:src="@drawable/circle" />

    <TextView
        android:id="@+id/text_view_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/image_view"
        android:text="text_1"
        android:textColor="@android:color/black" />

    <TextView
        android:id="@+id/text_view_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text_view_1"
        android:layout_toRightOf="@+id/image_view"
        android:text="text_2"
        android:textColor="@android:color/black" />

    <TextView
        android:id="@+id/text_view_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text_view_2"
        android:layout_toRightOf="@+id/image_view"
        android:text="text_3"
        android:textColor="@android:color/black" />

    <TextView
        android:id="@+id/text_view_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text_view_3"
        android:layout_toRightOf="@+id/image_view"
        android:text="text_4"
        android:textColor="@android:color/black" />
</RelativeLayout>

Output:

enter image description here