Android - 创建动画“向上拖动以锁定”

发布于 2024-12-01 08:33:18 字数 427 浏览 0 评论 0原文

有没有人知道如何创建像 Pocket App,用户可以从屏幕底部一直向上拖动一个小栏(如通知栏),使应用程序锁定自身并更改当前活动?

我只是想知道如何制作动画,如果它是android中的内置东西,或者更复杂的东西。有人可以指导我如何搜索/构建类似的动画吗?

对于那些不熟悉动画并且不了解该应用程序/不明白我的描述的人,可以查看它 这里

谢谢大家。

Does anyone have even a remote idea of how to create an animation like the one shown in the Pocket App where the user can drag a small bar (like the notification bar) from the bottom of the screen all the way up, making the app lock itself and change the current activity?

I'm just wondering how to do the animation, if it is a built in thing in android, or something more complexe. Can anyone give me some guidance of how to search/build a similar animation, please?

For those who are not familiar with the animation and do not know the app /did not understand my description, you can see it here

Thanks guys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯角 2024-12-08 08:33:19

你可以试试滑动抽屉。

或者对于这种类型的动画,您将需要一个放置在底部的布局并添加一个 onThumbTouchListener。

像这样的

OnTouchListener onThumbTouch = new OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event) 
        {   
            switch(v.getId())
            {
                case R.id.slider_thumb_id:
                {
                    switch(event.getAction())
                    {
                        case MotionEvent.ACTION_MOVE:
                        {                           
                            if(v.getTop()>=0 && v.getBottom()<sliderFrame.getMeasuredHeight()){
                                int topPos = (int)event.getRawY()-(v.getHeight()*2+v.getHeight());
                                if(topPos < 0) {
                                    topPos=0;
                                } else if(topPos > (sliderFrame.getMeasuredHeight()-v.getMeasuredHeight())){
                                    topPos = (sliderFrame.getMeasuredHeight()-v.getMeasuredHeight()) -1;
                                }   
                                iconParams.topMargin = topPos;
                                v.setLayoutParams(iconParams);
                                sliderThumbFake.setLayoutParams(iconParams);
                            }                           
                            break;
                        }
                        case MotionEvent.ACTION_UP:
                        {                           

                        }
                    }
                    break;
                }
            }
            return true;
        }
    };

案例语句中的代码可能没有用,因为它是我根据我的要求起诉的。但这就是拖动视图的方法。

You could tryout the sliding drawer.

Or for this sort of animation you will need a layout which you place in the bottom and add a onThumbTouchListener.

Something like this

OnTouchListener onThumbTouch = new OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event) 
        {   
            switch(v.getId())
            {
                case R.id.slider_thumb_id:
                {
                    switch(event.getAction())
                    {
                        case MotionEvent.ACTION_MOVE:
                        {                           
                            if(v.getTop()>=0 && v.getBottom()<sliderFrame.getMeasuredHeight()){
                                int topPos = (int)event.getRawY()-(v.getHeight()*2+v.getHeight());
                                if(topPos < 0) {
                                    topPos=0;
                                } else if(topPos > (sliderFrame.getMeasuredHeight()-v.getMeasuredHeight())){
                                    topPos = (sliderFrame.getMeasuredHeight()-v.getMeasuredHeight()) -1;
                                }   
                                iconParams.topMargin = topPos;
                                v.setLayoutParams(iconParams);
                                sliderThumbFake.setLayoutParams(iconParams);
                            }                           
                            break;
                        }
                        case MotionEvent.ACTION_UP:
                        {                           

                        }
                    }
                    break;
                }
            }
            return true;
        }
    };

The code inside the case statements might not be useful as it was something I sued for my requirement. But this how you do a drag of a view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文