我正在尝试展开折叠工具栏。我现在可以在释放我的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;
}
这段代码让我的酒吧在几乎崩溃时崩溃了...... 如何在它几乎展开时向下滚动?
答案 0 :(得分:1)
这是你应该做的:
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);