Fragment中RecyclerView完善

这篇博客详细介绍了在Fragment中如何完美地集成RecyclerView,包括item_layout.xml布局文件、fragment_1.xml布局、FragmentOne.java的Java代码实现、CollectRecycleAdapter.java自定义适配器以及GoodsEntity.java的数据实体类。通过这五个关键文件的配置,实现了RecyclerView的完整功能。
摘要由CSDN通过智能技术生成

总是五个文件

两个XML和三个JAVA(和正规教程里面把adapter分为adapter和entity两部分了)

先贴两个xml

1:item_layout.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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="6dp">

    <ImageView
        android:id="@+id/item_goods_img"
        android:layout_width="50dp"
        android:layout_height="50dp"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="vertical">


        <TextView
            android:id="@+id/item_goods_name"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:text="TextView"
            android:textSize="15dp" />

        <TextView
            android:id="@+id/item_goods_price"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:text="TextView"
            android:textSize="15dp" />
    </LinearLayout>
</LinearLayout>

2:fragment_1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="
  • 8
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 14
    评论
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值