【Android】RecycleView的学习笔记

RecycleView的学习笔记

本篇内容是学习笔记,不代表是最好的方案,不保证所有方法的理解正确。
欢迎各位大佬指正,优化。

学习假想环境是一个冰箱保存内容的管理App。
数据:食品的名称,放入时间,到期时间。如果已经过期,标记为Bad。

一、创建画面

在activity的xml文件中放入RecycleView控件。
红色框的部分是RecycleView
image

代码中包括两个部分,TextView是Title,RecycleView有多个版本,此处使用androidx的版本。

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/home_things_list_title"
            android:textSize="24sp" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/home_things_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

二、创建RecycleView的条目布局

下图中包含五个元素,第1和4元素是image,用于显示图片。第2元素是TextView。第3和5元素是EditText。
image

源代码如下:

<?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="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center|start">

    <ImageView
        android:id="@+id/things_list_status"
        android:layout_width="@dimen/home_things_list_item_image_height"
        android:layout_height="@dimen/home_things_list_item_height"
        android:contentDescription="@string/home_things_list_item_status"
        app:srcCompat="@mipmap/good" />

    <TextView
        android:id="@+id/things_list_name"
        style="@android:style/Widget.Material.TextView"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/home_things_list_item_height"
        android:text="@string/home_things_list_item_name"
        android:textColor
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值