views:

349

answers:

2

Hi I have a ImageView that needs to be slide in from the bottom. Remain there for 5 sec. And then slide out. How do I do that? There is no user intervention.

Thanks Rajesh Muthu

+1  A: 

Ok I found out a solution. Create an xml in anim folder called popup_slider.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true">
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0"  android:duration="100" />
    <translate android:fromYDelta="100%p" android:toYDelta="0%p"   android:startOffset="1000" android:duration="5000" android:zAdjustment="top"/>
    <alpha android:fromAlpha="0.99" android:toAlpha="1.0" android:startOffset="6000" android:duration="5000" />
    <translate android:fromYDelta="0%p" android:toYDelta="100%p"  android:startOffset="11000"  android:duration="5000" android:zAdjustment="bottom"/>    
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0"  android:startOffset="16000"  android:duration="1000" />
</set>

In Java implement AnimationListener

public static void popUpAndDownAnimation(View v) {

Animation animation = AnimationUtils.loadAnimation(localContext, R.anim.popup_slider);  

    animation.setAnimationListener(new Animation.AnimationListener(){
    public void onAnimationEnd(Animation arg0) {
        popUpAdvertisementView.setVisibility(View.GONE);                    
    }
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub              
    }
    public void onAnimationStart(Animation animation) {
        popUpAdvertisementView.setVisibility(View.VISIBLE);             
    }           
    });
    v.startAnimation(animation);
}
A: 

Android has a set of animation classes for simple animations on Views. What you're looking for is a tween animation. They provide an example, and it sounds like you could do most of it in XML. Good luck ^_^

paul.meier