【问题标题】:Android: Autocomplete animation for CollapsingToolbarLayoutAndroid:CollapsingToolbarLayout 的自动完成动画
【发布时间】:2015-10-14 19:59:41
【问题描述】:

我正在使用来自Android Design Support LibraryCollapsingToolbarLayout 在活动中为工具栏设置动画。问题是,如果我在动画中间抬起手指,工具栏不会继续动画。它只是在屏幕上显示一半。我该如何解决?

这是一个 gif:http://goo.gl/GQGQqe

感谢您的回答。

【问题讨论】:

    标签: android animation toolbar android-collapsingtoolbarlayout


    【解决方案1】:

    据我了解,您正在经历的行为是预期的。但是,有一个setExpanded() 方法允许您以编程方式关闭/打开AppBarLayout,并可以选择为进程设置动画。因此,您可以监听MotionEvent.ACTION_UP 事件并根据AppBar 从其原始位置移动的距离启动动画以打开或关闭它。

    编辑: 这是我刚刚在运行 KitKat 的模拟器上测试的一个实现:

    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);
        }
        //...
    }
    

    【讨论】:

      【解决方案2】:

      这可能会稍晚一点,但就像这篇文章中解释的那样:How to implement snapping in CollapsingToolbarLayout? 添加了一个新的捕捉功能。只需添加 应用程序:layout_scrollFlags="scroll|exitUntilCollapsed|snap" 到您的 CollapsingToolbarLayout。希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-17
        • 2012-12-29
        • 2010-12-18
        • 1970-01-01
        • 2015-08-20
        • 2018-07-14
        • 2020-05-21
        • 2016-07-12
        相关资源
        最近更新 更多