![](/img/trans.png)
[英]RecyclerView doesn't animate when it's inside a NestedScrollView
[英]How to animate nestedscrollview to bottom
我正在嘗試展開折疊工具欄。 現在,當我釋放Nestedscrollview時,我可以折疊工具欄,並且幾乎折疊了。 問題是,我不知道如何為擴展設置動畫效果,因為我幾乎將其發布。
這是我的代碼:
nestedScrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_UP:
Log.d("Touch", "Toque down");
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
if (behavior != null) {
Log.d("Touch", "Behavior chamado");
if(isCompressed) {
behavior.onNestedFling(coordinatorLayout, appBarLayout, null, 0, 10000, true);
} else{
//How can I make it go down??
}
}
return false;
}
Log.d("Touch", "Toque");
return false;
}
這段代碼使我的欄幾乎在折疊時塌陷... 如何在其幾乎展開時向下滾動?
這是您應該做的:
NestedScrollView nestedScrollView = (NestedScrollView)getActivity().findViewById(R.id.your_nested_scroll_view);
int toolbarHeight = getActivity().findViewById(R.id.toolbar).getHeight();
nestedScrollView.startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
nestedScrollView.dispatchNestedPreScroll(0, toolbarHeight, null, null);
nestedScrollView.dispatchNestedScroll(0, 0, 0, 0, new int[]{0, -toolbarHeight});
nestedScrollView.scrollTo(0, nestedScrollView.getBottom());
或者您可以使用:
nestedScrollView.fullScroll(View.FOCUS_DOWN);
nestedScrollView.fullScroll(View.FOCUS_UP);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.