上面我们介绍的就是?RecyclerView 线性布局的使用,效果还是不错的,一般可以用于浏览个人信息列表操作。接着,我们来看第二种布局形式:网格布局。
? ? 网格布局也是非常常用的,一般用于图片相册的浏览,接下来的工作就是复制粘贴一下原先的代码就可以了,因为适配器里面的代码几乎一个样,我们可以考虑把它封装起来用,不过现在还是怎么方便怎么来。
? ? 对于线性布局来说,网格布局是需要做一定量的修改的,也就是布局文件的修改,我们把旁边的 “我是一只...” 文本给去掉,保留了图片和动物名称,所以布局文件代码修改为:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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="180dp"
    android:layout_margin="8dp"
    app:cardCornerRadius="8dp"
    app:cardElevation="4dp">
 
    <RelativeLayout(http://www.my516.com)
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="8dp">
 
        <ImageView
            android:id="@+id/img_recy_item_2_pic"
            android:layout_width="match_parent"
            android:layout_height="120dp"
            android:scaleType="centerCrop" />
 
        <TextView
            android:id="@+id/tv_recy_item_2_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/img_recy_item_2_pic"
            android:layout_centerInParent="true"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:textSize="18sp" />
 
    </RelativeLayout>
</android.support.v7.widget.CardView>
--------------------- 
原文:https://www.cnblogs.com/hyhy904/p/11359731.html