Android PagerSnapHelper改造RecyclerView为ViewPage,kotlin
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity" />
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var rv = findViewById<RecyclerView>(R.id.recycler_view)
var layoutManager: LinearLayoutManager = LinearLayoutManager(this).apply {
this.orientation = LinearLayoutManager.HORIZONTAL
}
rv.layoutManager = layoutManager
var adapter = MyAdapter()
rv.adapter = adapter
//这将会让RecyclerView滚动时候完整展示一个item
//val snapHelper = LinearSnapHelper()
//snapHelper.attachToRecyclerView(rv)
//这将会使RecyclerView滚动的效果如图ViewPager2一样
val snapHelper = PagerSnapHelper()
snapHelper.attachToRecyclerView(rv)
//启动后将RecyclerView移到到指定位置。
layoutManager.scrollToPositionWithOffset(5, 0)
}
class MyAdapter : RecyclerView.Adapter<MyVH>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyVH {
var view = LayoutInflater.from(parent.context)
.inflate(android.R.layout.simple_list_item_2, parent, false)
view.setBackgroundColor(Color.LTGRAY)
view.minimumHeight = 800
return MyVH(view)
}
override fun getItemCount(): Int {
return Int.MAX_VALUE
}
override fun onBindViewHolder(holder: MyVH, position: Int) {
holder.t1.text = "$position"
holder.t2.text = "@$position"
}
}
class MyVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
var t1: TextView = itemView.findViewById(android.R.id.text1)
var t2: TextView = itemView.findViewById(android.R.id.text2)
init {
t1.textSize = 50.0f
t2.textSize = 30.0f
}
}
}
Android:GestureDetector.SimpleOnGestureListener,onFling,onScroll,velocityX,Y&distanceX,Y,kotlin_zhangphil的博客-CSDN博客Android不用OnScrollListener采用GestureDetector结合OnTouchListener实现ListView下拉/上拉刷新通常Android的ListView的下拉/上拉刷新实现,使用OnScrollListener比较简单,比如如果要实现下拉见顶刷新,思路是在OnScrollListener判断当前ListView的滚动状态,如果滚动停止,则将此时Lis。https://blog.csdn.net/zhangphil/article/details/130812011
Android RecyclerView measureTimeMillis Glide GridLayoutManager,kotlin_zhangphil的博客-CSDN博客基于Android官方Paging Library的RecyclerView分页加载框架我之前写了一篇RecyclerView分页加载机制的文章,是基于Android官方的AsyncListUtil实现的,详情见附录文章1。基于Android官方Paging Library的RecyclerView分页加载框架我之前写了一篇RecyclerView分页加载机制的文章,是基于Android官方的AsyncListUtil实现的,详情见附录文章1。【代码】Android Paging 3,kotlin(1)https://blog.csdn.net/zhangphil/article/details/131051138Android ViewPager2嵌套RecyclerView性能优化RecycledViewPool,kotlin_zhangphil的博客-CSDN博客ViewPager2和Fragment新的可见性及懒加载解决方案,旨在解决ViewPager(ViewPager2)只有当前Fragment唯一可见时候网络刷新或绘图。注意:过去的setUserVisibleHint()已被废弃,开发者不要再使用基于setUserVisibleHint()解决Fragment可见性和懒加载(或延迟加载)的场景。ViewPager2和Fragment可见性及懒加载解决方案_viewpager2 懒加载_zhangphil的博客-CSDN博客。https://blog.csdn.net/zhangphil/article/details/131231747