Search code examples
androidandroid-layoutlistview

How to make split listview


Hello everyone first of all me english is bad , so i will do my best to devliver what i want to do in my listview.

anyway i have a listview , i need to split into two sides. (left - right) like this image an example -----> https://ibb.co/dotxS5

this is my layout code.

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tasneem.coustomlistview.MainActivity">

<ListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

</LinearLayout>

and this is my row-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="match_parent">
<ImageView
    android:id="@+id/Image"
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:src="@mipmap/ic_launcher"
    android:layout_marginStart="15dp"
    android:layout_marginTop="24dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true" />
  <TextView
      android:id="@+id/name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="name"
      android:textSize="25dp"
      android:layout_alignBottom="@+id/Image"
      android:layout_toEndOf="@+id/Image"
      android:layout_marginStart="38dp" />

</RelativeLayout>

I just want to do the above following in layouts.

Thank you.


Solution

  • Consider using RecyclerView instead of ListView.

    With RecyclerView you can easily create a grid with GridLayoutManager.

    myRecyclerView.setLayoutManager(new GridLayoutManager(context, numberOfColumns);
    myRecyclerView.setAdapter(myAdapter);