当前位置:网站首页>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 )》
边栏推荐
- W10 add system environment variable path
- Security框架中使用FastJson反序列化SimpleGrantedAuthority
- 婴儿名字[连通分量之邻接矩阵与DFS]
- 《安富莱嵌入式周报》第270期:2022.06.13--2022.06.19
- [pwn基础]Pwntools学习
- [comprehensive pen test] difficulty 2.5/5: "tree array" and "double tree array optimization"
- R language uses GLM function to build Poisson regression model, and coef function to obtain the coefficients of Poisson regression model and analyze the effects of various variables
- Manjaro installs the downloaded TTF font file
- ThreadLocal与线程池在使用中可能会出现的两个问题
- Source code analysis of ArrayList
猜你喜欢

Gradle download and installation configuration

Forwarding to remind metamask how to deal with the potential private key disclosure of the expansion program

Use the uniapp framework to build the zheliban micro application (single sign on, embedded point, aging adaptation, RPC gateway)

NPDP|如何做好产品生命周期管理?

An accident caused by a MySQL misoperation, and the "high availability" cannot withstand it!

如何在Chrome浏览器中模拟请求或修改请求的域名

With a playback volume of up to 4000w+, how do couples get out of the ring by scattering dog food?

MFC interface library bcgcontrolbar v33.0 - Desktop alert window, grid control upgrade

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

删除倒数第k个节点-链表专题
随机推荐
2022年6月25日PMP考试通关宝典-4
6月25日PMP考前指南,你需要做好这些
W10添加系统环境变量Path
With a playback volume of up to 4000w+, how do couples get out of the ring by scattering dog food?
删除倒数第k个节点-链表专题
机器学习之贝叶斯分类与集成学习
[comprehensive pen test] difficulty 2.5/5: "tree array" and "double tree array optimization"
新手使用APICloud可视化开发搭建商城主页
2022年下半年传统产品经理国际资格认证招生简章(NPDP)
Introduction to setting program icon in QT
Nepal graph has settled in Alibaba cloud computing nest to help enterprises build a super large-scale map database on the cloud
Flink 系例 之 TableAPI & SQL 与 示例模块
基于k近邻的MNIST图像分类对比
[pwn基础]Pwntools学习
出院小结识别api接口-医疗票据OCR识别/出院诊断记录/电子病历/理赔服务
[high frequency interview questions] the difficulty is 1.5/5. Common two point double pointer interview questions
R language uses neuralnet package to build neural network regression model (feedforward neural network regression model), visualize the scatter diagram between the actual target value and the predicte
Manjaro installs the downloaded TTF font file
谷粒学院P40~43
如何在Chrome浏览器中模拟请求或修改请求的域名