利用XrecycleView写多条目展示+流式布局

本文介绍了如何在Android项目中利用XrecycleView库创建多条目展示,并配合流式布局。首先,引入所需依赖并解决build错误,接着在清单文件添加权限。XML布局文件设计了首页流式布局和圆角Text条目。然后,展示了用于不同条目展示的三种布局。在MainActivity中实现显示,并在Adapter中完成数据绑定。最后,展示了实现后的效果图。
摘要由CSDN通过智能技术生成

首先我们先引入我们所需要的依赖

//流失布局需要的依赖
implementation 'com.hyman:flowlayout-lib:1.1.2'
    implementation 'com.android.support:design:28.0.0'
    //recycler的依赖
    implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
//okgo
    implementation 'com.lzy.net:okgo:3.0.4'
//Glide加载图片
    implementation 'com.github.bumptech.glide:glide:3.7.0'
	//解析数据
    implementation 'org.kie.modules:com-google-code-gson:6.5.0.Final'
    //xrecycle
    implementation 'com.jcodecraeer:xrecyclerview:1.5.9'

如果build报错在最外层gradle加入

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

其次是清单文件写权限

//联网权限
 <uses-permission android:name="android.permission.INTERNET" />
    //写
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
   //读
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

首页显示的流式布局 xml布局

 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="搜索历史"
        android:textSize="30sp"
        />
    <com.zhy.view.flowlayout.TagFlowLayout
    android:id="@+id/id_flowlayout"
    app:max_select="-1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="20dp">
</com.zhy.view.flowlayout.TagFlowLayout>

需要写一个圆角的text条目

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:background="@drawable/shape"
    android:text="Helloworld"
    android:textColor="#000"
    android:textSize="20sp"
    android:padding="10dp"
    >
</TextView>

下方是显示多条目的布局

 <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:id="@+id/recycle1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ></com.jcodecraeer.xrecyclerview.XRecyclerView>

下方就是recyleView的多条目的三种布局
第一种布局

<LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="100dp"
       android:orientation="vertical"
       android:layout_weight="1"
       >
       <TextView
           android:id="@+id/text_name"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="TextView"
           android:textSize="25sp"
           />
       <TextView
           android:id="@+id/text_time"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="TextView"
           android:textSize="15sp"
           android:textColor="#6666"
           />
   </LinearLayout>
    <ImageView
        android:id="@+id/image_icon"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@mipmap/ic_launcher"
        />

第二种布局

<Line
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值