简介
使用RecyclerView实现网格布局,实现手机界面应用列表
效果
效果如下图:
详细代码
XML布局文件
在布局中使用RecyclerView控件
activity_main.xml
<?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"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#9709F7">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
RecyclerView子项列表布局
recyclerview_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="220dp"
android:layout_height="220dp"
android:background="#20FDFDFD"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_margin="20dp">
<ImageView
android:id="@+id/iv_apply_image"
android:layout_width="112dp"
android:layout_height="112dp"
android:layout_marginTop="32dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/tv_a