Rajkiran
Rajkiran

Reputation: 16193

Fade layout as it slides in slide-out menu

I have a custom slide-out menu implementation (not using any library) in which I slide my layout towards right and show menus on the left (like facebook, google+ app does). After the menu is shown I fade the right layout by giving some alpha value as shown in the code below:

    <FrameLayout
        android:id="@+id/fl_mask"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:alpha="0.7"
        android:background="@color/black">
    </FrameLayout>

But this all happens when my menu is shown. What I want is, as the layout slides towards right, I want to darken it. Farther the layout from left edge, darker the layout. Moreover, I use following code for layout animation which slides my layout towards right.

public Animation SlidingAnimation(int animateDuration, boolean slideLeftToright, final boolean executeOnAnimEndCode) {
    Animation animation = null;
    AnimationSet set = new AnimationSet(true);

    if (slideLeftToright) {
        animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.0f);
    } else {
        animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.0f);
    }

    animation.setDuration(animateDuration);

    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (executeOnAnimEndCode) {
                               ... // Some piece of code
            }
        }
    });
    set.addAnimation(animation);

    return animation;
}

How can I fade/darken my layout as it slides towards right?

Upvotes: 2

Views: 1045

Answers (1)

Muhammad Babar
Muhammad Babar

Reputation: 8124

In your

public void onAnimationEnd(Animation animation) 
{
            if (executeOnAnimEndCode) 
            {
               AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f);

               alphaAnimation.setFillAfter(true);

               someLayout.startAnimation(alphaAnimation);
            }
        }
    });

or you can also declare animation as xml and then use it....

Upvotes: 1

Related Questions