【问题标题】:navigation drawer Animation android导航抽屉动画android
【发布时间】:2015-03-22 07:00:26
【问题描述】:

我是安卓新手。我对 Android 导航抽屉有疑问。我在我的应用程序中包含了 Navigation Drawer,一切正常,但我想知道是否有人可以帮助我在导航抽屉列表中获取惰性动画。

Source of the image.

谢谢。

【问题讨论】:

    标签: android android-animation navigation-drawer


    【解决方案1】:

    也许有更好的方法,但我偶然发现了这一点。可以通过 RecyclerView 实现延迟滑入效果,并在 onBindViewHolder 方法中设置动画。

    下面的代码改编自“如何在 RecyclerView 项目出现时设置动画”。我对其进行了调整,以根据位置错开动画。您还需要在调用初始可见视图的所有位置后停止调用 setAnimation 方法的逻辑,除非您希望它们在用户滚动时从左侧滑入。

    How to animate RecyclerView items when they appear(改编)

    @Override
    public void onBindViewHolder(ViewHolder holder, int position)
    {
        holder.text.setText(items.get(position));
    
        // Here you apply the animation when the view is bound
        setAnimation(holder.container, position);
    }
    
    /**
     * Here is the key method to apply the animation
     */
    
    private void setAnimation(View viewToAnimate, int position)
    {
            Context context = MyApp.getActivity();
            Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left);
    
            animation.setDuration(position * 50 + 200);
            viewToAnimate.startAnimation(animation);
    
    }
    

    动画太多视图可能会变得非常不稳定顺便说一句。增加间隔延迟会在更早的动画时留下更多的屏幕外。您可以尝试找到一些动画(除了默认的 android 动画),让它们更多地离开屏幕(例如暂停、然后移动或加速动画),这样您就可以更好地控制一次在屏幕上动画的视图数量。

    【讨论】:

    • 这个解决方案似乎有效,或者至少给了我一个起点。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 2015-09-30
    相关资源
    最近更新 更多