Android使用LRecyclerView实现线性流资讯页

本文介绍了如何在Android应用中使用LRecyclerView库创建一个线性流的资讯页面,包括下拉刷新和上拉加载功能。通过在build.gradle文件中添加依赖,并设置布局及自定义ListView样式,然后创建适配器来处理数据绑定,实现了所需功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在进行毕业设计,想要做一个线性流的资讯页面,在网上找了一下,好像对这块的描写都不太清楚。
这个是最终的效果
在这个demo中我需要实现下拉刷新,上拉加载等。
首先导入github大神的开源库:
GitHub地址:https://github.com/jdsjlzx/LRecyclerView/

Step 1. 在你的根build.gradle文件中增加JitPack仓库依赖。

allprojects {
   
    repositories {
   
        jcenter()
        maven {
    url "https://jitpack.io" }
    }
}

Step 2. 在你的module的build.gradle文件中增加LRecyclerView依赖。

implementation 'com.github.jdsjlzx:LRecyclerView:1.5.4.3'

在这里我先把布局给安排好:
这个xml页面用来放置一整个LRecyclerView,我打算整个页面都用于资讯页,因此高度用了wrap_content,需要自定义其他功能的可以自己加。

<?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">

    <com.github.jdsjlzx.recyclerview.LRecyclerView
        android:id="@+id/lrv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    </com.github.jdsjlzx.recyclerview.LRecyclerView>
</LinearLayout>

接着再新建一个xml文件,在这个页面上,我们要放置你的单个ListView样式我这里是这样设置

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@color/color_hint"
    android:padding="5dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <LinearLayout
        android:padding="5dp"
        android:background="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <ImageView
            android:id="@+id/iv_icon"
            android:layout_width="160dp"
            android:layout_height="120dp"
            android:gravity="left"
            android:scaleType="fitXY">
        </ImageView>

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="8dp"
            android:text="官宣!首尔马拉松宣布赛事取消 全额退还报名费"
            android:textAllCaps="false"
            android:textColor="@color/black"
            android:textSize="24sp">

        </TextView>
    </LinearLayout>

</RelativeLayout>

在这个xml内,你可以自己调节样式的摆放,接下来每个生成都会这个样子。

接下来我们需要添加一个适配器adapter,我们的数据添加与修改都要通过这个适配器。

public class DataAdapter extends LRecyclerView.Adapter<DataAdapter.RecyclerViewHodler> {
   

    private final Context context;
    private ArrayList<String> datas;
    private Bitmap[] bitmaps;
    private ArrayList<String> urls;

    public DataAdapter(Context context) {
   
        this.context = context;
    }

    /**
     * 这里找到你的listview
     * @param parent
     * @p
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值