vin
vin

Reputation: 337

Sliding Drawer Animation

I need to decrease the opacity of the background of the sliding drawer as and when the slider is opening and increase the opacity when closing.

Tried Changing the background when slider is open/closed SlidingDrawer.OnDrawerOpenListener/SlidingDrawer.OnDrawerCloseListener , its not what i'm looking for.

Any help is much appreciated.

Upvotes: 0

Views: 962

Answers (1)

Ali Imran
Ali Imran

Reputation: 9217

Here is a example try this :

Fading color effect with TransitionDrawable

RelativeLayout layout = (RelativeLayout) findViewById(R.id.Layout);
layout.setBackgroundResource(R.drawable.translate);
TransitionDrawable transition = (TransitionDrawable) layout.getBackground();
transition.startTransition(5000);

This code gives you a fading effect like from yellow to white(original color).

translate.xml

<?xml version="1.0" encoding="UTF-8"?>
   <transition xmlns:android="http://schemas.android.com/apk/res/android">
          <!-- The drawables used here can be solid colors, gradients, shapes, images, etc. -->
          <item android:drawable="@drawable/new_state" />
          <item android:drawable="@drawable/original_state" />
   </transition>

new_state.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape   xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
    <solid android:color="#FFFFA7"/>
</shape>

original_state.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape   xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
    <solid android:color="#FFFFFF"/>
</shape>

Upvotes: 2

Related Questions