Android淡入/淡出动画从下到上

时间:2017-06-26 04:55:37

标签: android android-layout animation android-animation

我正在创建一个动画,其中我想淡出我的图像视图,但是淡入淡出的动画应该从下到上开始,而不像整个图像视图一次淡出的淡入淡出动画。

public void animateFadeIn() {
    Animation in = AnimationUtils.loadAnimation(this,
            android.R.anim.fade_in);
    motherboard.startAnimation(in);
    motherboard.setVisibility(View.VISIBLE);
    in.setDuration(1500);
    in.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // TODO Auto-generated method stub
            animateFadeOut();
        }
    });
}

如何实现这一目标。

<?xml version="1.0" encoding="UTF-8"?>

<scale
    android:fromYScale="-450"
    android:toYScale="450" />

<alpha
    android:duration="1500"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:repeatCount="infinite"
    android:toAlpha="1.0" />

1 个答案:

答案 0 :(得分:1)

中创建一个slide_up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
    android:duration="5000"
    android:fillAfter="true"
    android:fromYDelta="75%p"
    android:repeatCount="0"
    android:toYDelta="0%p" />

你的fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >

   <alpha
    android:duration="1000"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="1.0" />

</set>

比加载动画

ImageView imageview;
Animation animFadein, animslideup;

animFadein = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.fade_in);
    animslideup = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.slide_up);

 final AnimationSet s = new AnimationSet(true);
    s.setInterpolator(new AccelerateInterpolator());

    s.addAnimation(animslideup);
    s.addAnimation(animFadein);
    imageview.startAnimation(s);