记账APP模块功能要点解析——主页功能要点

RecyclerView及适配器功能的用法

 <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv1"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        android:orientation="horizontal"
        android:layout_marginHorizontal="20dp"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

RecyclerView的适配器
定义一个函数

private fun initRv2(){
	val mutableListOf = mutableListOf<String>(
            "Simon",
            "Dion",
            "Sam",
            "Chris",
            "Simon",
            "Dion",
            "Sam",
            "Chris",
        )
	binding.rv1.adapter = RvA(mutableListOf, R.layout.item02) { itemData, position, view ->
            Item02Binding.bind(view).apply {
                when (itemData) {
                    "Simon" -> image.setImageResource(R.drawable.y1)
                    "Dion" -> image.setImageResource(R.drawable.y2)
                    "Sam" -> image.setImageResource(R.drawable.v1)
                    "Chris" -> image.setImageResource(R.drawable.v2)
                }
                text.text = itemData
                del.visibility = View.GONE
                image.setOnClickListener {
                    del.visibility = View.VISIBLE
                    del.setOnClickListener {
                        mutableListOf.removeAt(position)
                        dataList = mutableListOf
                        notifyItemRemoved(position)
                        notifyItemChanged(position, mutableListOf.size)
                    }
                }
            }
        }
}

写出recycleview的子项 item02

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_marginVertical="10dp"
    android:layout_marginHorizontal="20dp"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="70dp"
        android:layout_height="70dp">


        <androidx.constraintlayout.utils.widget.ImageFilterView
            android:layout_width="match_parent"
            android:src="@drawable/source13"
            android:scaleType="centerCrop"
            app:round="10dp"
            android:id="@+id/image"
            android:layout_height="match_parent"/>

        <androidx.constraintlayout.utils.widget.ImageFilterView
            android:layout_width="match_parent"
            android:src="@drawable/del"
            android:padding="20dp"
            app:round="10dp"
            android:id="@+id/del"
            android:scaleType="centerCrop"
            android:background="@color/black_2a"
            android:layout_height="match_parent"/>

    </androidx.constraintlayout.widget.ConstraintLayout>

    <TextView
        android:text="你问问阿萨德"
        android:id="@+id/text"
        android:textSize="13dp"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晚风时亦鹿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值