简体   繁体   中英

navigation drawer Animation android

I am new to android. I have a problem regarding Android Navigation Drawer. 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.

The code below is adapted from the "how to set animation on RecyclerView items when they appear." 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.

How to animate RecyclerView items when they appear (adapted)

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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