[英]Is it possible to programmatically scroll to a child of on appbarlayout?
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<Toolbar/>
</CollapsingToolbarLayout>
<View1/>
<View2/>
<View3/>
</AppBarLayout>
<RecyclerView/>(app_bar_scrolling_behavior)
</CoordinatorLayout>
我想以編程方式滾動到 view3 對 recyclerview 中的某個項目執行某些操作。對此有任何解決方案嗎?
能夠使用以下代碼片段通過使用值動畫師來實現這一點。 `
recyclerview.scrollToPosition(0)
val params = appbar.layoutParams as CoordinatorLayout.LayoutParams
val behavior = params.behavior as AppBarLayout.Behavior?
if (behavior != null) {
val valueAnimator: ValueAnimator = ValueAnimator.ofInt()
valueAnimator.interpolator = DecelerateInterpolator()
valueAnimator.addUpdateListener { animation ->
behavior.topAndBottomOffset = (animation.animatedValue as Int)
appBar.requestLayout()
}
valueAnimator.setIntValues(
0, -appbar.totalScrollRange + view3.root.measuredHeight
)
valueAnimator.duration = 50
valueAnimator.start()
}
`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.