Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

navigation drawer with animation

Source of the image.

Thank you.

like image 203
tintin21 Avatar asked Mar 22 '15 07:03

tintin21


1 Answers

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 (e.g. pause, then move, or accelerating ones), so you can better control how many views at once are being animated on screen.

like image 198
NameSpace Avatar answered Oct 05 '22 03:10

NameSpace