我使用CollapsingToolbarLayout
从Android Design Support Library
为动画活动中的工具栏。问题是,如果我在动画中间抬起手指,工具栏不会继续动画。它只在屏幕上保持一半显示。我该如何解决它?Android:自动完成动画CollapsingToolbarLayout
这里是一个GIF:http://goo.gl/GQGQqe
谢谢回答。
我使用CollapsingToolbarLayout
从Android Design Support Library
为动画活动中的工具栏。问题是,如果我在动画中间抬起手指,工具栏不会继续动画。它只在屏幕上保持一半显示。我该如何解决它?Android:自动完成动画CollapsingToolbarLayout
这里是一个GIF:http://goo.gl/GQGQqe
谢谢回答。
您所遇到的行为是,据我所知,预计。然而,有一个setExpanded()
方法,它允许您以编程方式关闭/打开AppBarLayout
,并可以选择动画过程。因此,您可能可以听取MotionEvent.ACTION_UP
事件,并根据AppBar
从原始位置走过的距离发起动画以打开或关闭它。
编辑: 这是我刚刚在模拟器上测试的实施运行奇巧:
public class MainActivity extends AppCompatActivity {
//...
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_UP) {
if (appBarLayout.getY() != 0) {
//User has just finished interacting with the screen
//and the AppBar is not fully expanded. So, to close
//it with an animation...
appBarLayout.setExpanded(false, true);
}
}
return super.dispatchTouchEvent(ev);
}
//...
}
这可能是晚了一点,但就像在这篇文章中解释说:How to implement snapping in CollapsingToolbarLayout?添加了一个新的捕捉功能。只需添加 app:layout_scrollFlags =“scroll | exitUntilCollapsed | snap” 到您的CollapsingToolbarLayout。希望能帮助到你。
gif的链接已死 –