RecyclerView实现网格布局,仿应用列表

本文档介绍了如何使用Android的RecyclerView实现网格布局,以创建类似手机应用列表的效果。详细内容包括XML布局文件的设置、JAVA代码实现的GridAdapter及ApplyBean实体类,以及设置RecyclerView的布局管理和监听事件的方法。
摘要由CSDN通过智能技术生成

简介

使用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值