Commit ccabf673 authored by mengcuiguang2's avatar mengcuiguang2

代码优化

parent 982a6c58
......@@ -8,6 +8,8 @@ import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.scwang.smartrefresh.layout.api.RefreshLayout
......@@ -34,6 +36,7 @@ import com.mints.helivideo.utils.SpanUtils
import com.mints.library.utils.GlideUtils
import com.mints.library.utils.nodoubleclick.AntiShake
import kotlinx.android.synthetic.main.fragment_main.*
import java.lang.reflect.Field
import java.util.*
import kotlin.concurrent.schedule
......@@ -186,6 +189,7 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
vpAdapter = HomeVideoPageAdapter(tabsData, this)
vp2.adapter = vpAdapter
vp2.desensitization()
TabLayoutMediator(tablayout, vp2) { tab, position ->
// 初始化Tab
tab.id = position
......@@ -349,4 +353,17 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
}
}
fun ViewPager2.desensitization(){
//动态设置ViewPager2 灵敏度
try {
val recyclerViewField: Field = ViewPager2::class.java.getDeclaredField("mRecyclerView")
recyclerViewField.isAccessible = true
val recyclerView = recyclerViewField.get(this) as RecyclerView
val touchSlopField: Field = RecyclerView::class.java.getDeclaredField("mTouchSlop")
touchSlopField.isAccessible = true
val touchSlop = touchSlopField.get(recyclerView) as Int
touchSlopField.set(recyclerView, touchSlop * 3) //6 is empirical value
} catch (ignore: java.lang.Exception) {
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment