简体   繁体   English

导航抽屉动画android

[英]navigation drawer Animation android

I am new to android. 我是android的新手。 I have a problem regarding Android Navigation Drawer. 我有关于Android导航抽屉的问题。 I included Navigation Drawer in my app everything goes fine but i was wondering if anyone could help me to get lazy animation on navigation drawer list. 我在我的应用程序中包含导航抽屉一切顺利,但我想知道是否有人可以帮助我在导航抽屉列表上得到懒惰的动画。

带动画的导航抽屉

Source of the image . 图像来源

Thank you. 谢谢。

Maybe there's a better way, but I stumbled across this. 也许有更好的方法,但我偶然发现了这一点。 You can achieve the delayed-slide-in effect with a RecyclerView, and setting an animation in the onBindViewHolder method. 您可以使用RecyclerView实现延迟滑入效果,并在onBindViewHolder方法中设置动画。

The code below is adapted from the "how to set animation on RecyclerView items when they appear." 下面的代码改编自“如何在RecyclerView项目出现时设置动画”。 I adapted it to stagger the animation based on position. 我根据位置调整了动画。 You will also need logic to stop calling the setAnimation method after the all positions for the initially-visible views get called, unless you want them to slide in from the left as the user scrolls. 在调用初始可见视图的所有位置之后,您还需要逻辑来停止调用setAnimation方法,除非您希望它们在用户滚动时从左侧滑入。

How to animate RecyclerView items when they appear (adapted) 如何在RecyclerView项目出现时进行动画处理 (改编)

@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);

}

Animating too many views can get very choppy btw. 动画太多视图可能会变得非常不稳定。 Increasing the interval-delay leaves more off screen while earlier ones are animating. 增加间隔延迟会使屏幕更多,而早期的屏幕则会动画。 You might try finding some animations (besides the default android one) that would leave them off screen more (eg pause, then move, or accelerating ones), so you can better control how many views at once are being animated on screen. 您可能会尝试找到一些动画(除了默认的android之外),这会让他们离开屏幕更多(例如暂停,然后移动或加速),这样您就可以更好地控制一次在屏幕上设置动画的视图数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM