开发者

Automatic animation

开发者 https://www.devze.com 2022-12-21 05:37 出处:网络
I have a开发者_StackOverflow 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.

I have a开发者_StackOverflow 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


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);
}


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 ^_^

0

精彩评论

暂无评论...
验证码 换一张
取 消