Home > Back-end >  How to make a listview/recycleview like ios style on android
How to make a listview/recycleview like ios style on android

Time:07-06

I created a listview which display all the application installed on my phone, But I want to make it more similar to the listview of ios

My xml file

<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"
android:orientation="vertical">
<LinearLayout
    android:id="@ id/linear1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp"
    android:orientation="vertical">
    <TextView
        android:id="@ id/textview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:text="Applications"
        android:textSize="30sp"
        android:textStyle="bold"
        android:textColor="#000000"/>
    <ListView
        android:id="@ id/listview1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:background="@android:color/transparent"
        android:choiceMode="none"/>
</LinearLayout>

The listview I have

How to move the icon image to the left side of the center of listview divider (The x mark)

Sketch of what I want

CodePudding user response:

I think there is a left margin(or padding) attribute in the list cell. Please remove it.

or You can make a cell like this.

<RelativeLayout>
<LinearLayout> 
//icon and text content 
</LinearLayout> 
<TextView margin-left="32dp" BackgroundColor="#888"> 
//this will be the divider that has left margin
</TextView> 
</RelativeLayout>

CodePudding user response:

You should use RecyclerView for displaying a list of views. Recycler uses adapter for displaying multiple items. This code will help you build the same item.

<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout    xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
    android:id="@ id/ivICon"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:contentDescription="@null"
    android:src="@drawable/ic_launcher_background"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@ id/tvTitle"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:text="Title"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@id/ivICon"
    app:layout_constraintTop_toTopOf="parent" />

<View
    android:layout_width="0dp"
    android:layout_height="1dp"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    app:layout_constraintBottom_toBottomOf="@id/ivICon"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@id/ivICon"
    app:layout_constraintTop_toTopOf="@id/ivICon" /></androidx.constraintlayout.widget.ConstraintLayout>

Use this tutorial for Recycler View

  • Related