本文主要是介绍记账APP模块功能要点解析——主页功能要点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
RecyclerView及适配器功能的用法
<androidx.recyclerview.widget.RecyclerViewandroid: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 = itemDatadel.visibility = View.GONEimage.setOnClickListener {del.visibility = View.VISIBLEdel.setOnClickListener {mutableListOf.removeAt(position)dataList = mutableListOfnotifyItemRemoved(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.ConstraintLayoutandroid:layout_width="70dp"android:layout_height="70dp"><androidx.constraintlayout.utils.widget.ImageFilterViewandroid: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.ImageFilterViewandroid: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><TextViewandroid: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>
这篇关于记账APP模块功能要点解析——主页功能要点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!