最近刚学了RecyclerView的网格布局,刚好顺便写个Demo来加深一下印象。
首先是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"
android:background="#EFEDED"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
代码很简单,只添加了一个RecyclerView布局;
接着准备item的布局文件item_one_view_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@draw