Pada project android studio anda, di projec explorer sebelah kiri, tampilkan file res>layout >activity_main.xml, kemudian tulis atau masukan instruksi seperti di bawah ini:
File: activity_main.xml
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=”.MainActivity”>
android:id=”@+id/list_view”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
app:layout_constraintTop_toTopOf=”parent”
app:layout_constraintLeft_toLeftOf=”parent”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintRight_toRightOf=”parent”
android:dividerHeight=”0dp” />
Pada kode di atas kita menggunakan constraint layout, dimana list view kita buat full screeen dengan cara menawarkan nilai pada constraint batas atas,kiri, kanan dan bawahnya dengan parent agar menyesuaikan dengan lebar layar.
…
…
app:layout_constraintTop_toTopOf=”parent”
app:layout_constraintLeft_toLeftOf=”parent”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintRight_toRightOf=”parent”
…
…
Langkah 4:
Cara Membuat Custom list view dengan gambar icon dan teks di android studio Part 4
Buat file list_item.xml di folder res>layout>list_item.xml
Ini untuk desain setiap item dalam list, kurang lebih designnya akan seperti gambar ini:
Sebelah kiri foto, di kanan terdiri dari goresan pena nama, alamat dan pekerjaan.
Silahkan masukan atau copy kode di bawah ini
File: list_item.xml
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:padding=”10dp”
xmlns:app=”http://schemas.android.com/apk/res-auto”>
android:id=”@+id/photo”
android:layout_width=”100dp”
android:layout_height=”100dp”
app:layout_constraintLeft_toLeftOf=”parent”
app:layout_constraintTop_toTopOf=”parent”
app:layout_constraintBottom_toBottomOf=”parent”/>
android:id=”@+id/name”
android:layout_width=”0dp”
android:layout_height=”wrap_content”
app:layout_constraintLeft_toRightOf=”@id/photo”
app:layout_constraintTop_toTopOf=”parent”
android:padding=”5dp”
android:textStyle=”bold”
app:layout_constraintBottom_toTopOf=”@id/address”
app:layout_constraintRight_toRightOf=”parent”
app:layout_constraintVertical_chainStyle=”packed”/>