当前位置:网站首页>Recycleview lazy load failure
Recycleview lazy load failure
2022-06-21 19:58:00 【yufumatou】
Preface : When the amount of data is large ( Such as 200 More than ) Obviously feel APP Carton , Through investigation, it is found that RecycleView Adapter's onBindViewHolder Execute as many times as you have data , Sliding display lazy load failed .
reason :RecycleView Or the parent control is used horizontally android:layout_weight="1" Property will cause RecycleView Lazy loading is invalid
<?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="match_parent"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_test"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>class TestAdapter : RecyclerView.Adapter<TestAdapter.TestViewHolder>(){
private val testList = arrayListOf<String>()
init {
for (i in 1..500){
testList.add(" The first {$i} term ")
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TestViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_test, parent, false)
return TestViewHolder(view)
}
override fun getItemCount(): Int {
return testList.size
}
override fun onBindViewHolder(holder: TestViewHolder, position: Int) {
holder.tvItem.text = testList[position]
Log.e("aa", "***********$position")
}
class TestViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val tvItem = view.findViewById<TextView>(R.id.tv_item)
}
}rv_test.layoutManager = LinearLayoutManager(this)
rv_test.adapter = TestAdapter()programme : about RecycleView Need percentage in horizontal direction , Don't use “LinearLayout + layout_weight” programme , have access to “ConstraintLayout+layout_constraintWidth_percent” Instead of
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_test"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintWidth_percent="0.5"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintStart_toEndOf="@+id/rv_test"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>Last : There is another failure case 《RecycleView Lazy load failure ( Two )》
边栏推荐
- 机器学习之模型评估与选择
- LeetCode个人题解(剑指offer 21-25)21. 调整数组顺序使奇数位于偶数前面,22. 链表中倒数第k个节点,24. 反转链表,25. 合并两个排序的链表
- W10添加系统环境变量Path
- [high frequency interview questions] linked list interview questions with 1/5 difficulty and lower difficulty
- 论文解读(USIB)《Towards Explanation for Unsupervised Graph-Level Representation Learning》
- Nepal graph has settled in Alibaba cloud computing nest to help enterprises build a super large-scale map database on the cloud
- Use the uniapp framework to build the zheliban micro application (single sign on, embedded point, aging adaptation, RPC gateway)
- Move Protocol Beta测试版进行时,瓜分生态核心权益MOMO
- R语言glm函数构建二分类logistic回归模型(family参数为binomial)、使用summary函数查看模型汇总统计信息并解读特征
- Novice uses apiccloud visual development to build the mall home page
猜你喜欢

How to use devaxpress WPF to create the first MVVM application in winui?

How to set the picture background to transparent

Nepal graph has settled in Alibaba cloud computing nest to help enterprises build a super large-scale map database on the cloud

自定义代码模板

转发提醒 MetaMask小狐狸钱包安全公告 如何应对拓展程序潜在的私钥泄露

基于k近邻的MNIST图像分类对比

Nacos configuration center source code

剑指 Offer II 029. 排序的循环链表

CPDA|数据分析师需要具备哪些基本功?

W10 add system environment variable path
随机推荐
manjaro安装下载的ttf字体文件
Use the uniapp framework to build the zheliban micro application (single sign on, embedded point, aging adaptation, RPC gateway)
Novice uses apiccloud visual development to build the mall home page
Excel文件加密的两种方式
[pwn基础]Pwntools学习
Tableapi & SQL and example module of Flink
决策树的实现和调优(sklearn,GridSearchCV)
When the move protocol beta is in progress, the ecological core equity Momo is divided
谷歌浏览器80版本以后,如何处理出现的问题SameSite跨域问题
TensorFlow 2:使用神经网络对Fashion MNIST分类并进行比较分析
inno setup 窗口拖动学习
动态规划【二】(线性dp)
MySQL-CentOS安装MySQL8
API interface for discharge summary identification - medical bill OCR identification / discharge diagnosis record / electronic medical record / claim settlement service
yolov5训练自己的数据集报错记录
Startup mode of Jupiter notebook and related problems
Two ways of encrypting Excel files
论文解读(USIB)《Towards Explanation for Unsupervised Graph-Level Representation Learning》
記一些PAT題目(一)
SQL operation: with expression and its application