如何从屏幕外滑下徽标?

时间:2014-12-01 13:43:40

标签: android imageview android-animation

我试图在屏幕顶部显示徽标的闪屏,然后停在屏幕中央。

我在我的动画文件中使用XML:

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

    <translate
        android:fromYDelta="0%p"
        android:toYDelta="75%p"
        android:duration="3000" />
</set>

这种加载运动的方法:

Animation fadein = AnimationUtils.loadAnimation(getActivity(), R.anim.fadein);
background.startAnimation(fadein);
background.setVisibility(ImageView.VISIBLE);

// load the animation
Animation animMoveDown = AnimationUtils.loadAnimation(getActivity(), R.anim.movedown);

// set animation listener
animMoveDown.setAnimationListener(this);
overlay.startAnimation(animMoveDown);

如何将徽标放在屏幕上方并让它向下滑动到中心?有可能吗?

4 个答案:

答案 0 :(得分:2)

谢谢大家,就我而言,XML是:

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

    <translate
        **android:fromYDelta="-50%p"**
        android:toYDelta="75%p"
        android:duration="3000" />
</set>

答案 1 :(得分:1)

绝对可能!你将不得不玩这个,但你基本上只想从负YDelta开始

这是我在我的应用中使用的内容,我需要在屏幕上启动图像的最底部。

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

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="-84%"
        android:toYDelta="0%"
        android:duration="500" />
</set>

我想,你想要从-100%开始,以50%结束,所以试试这个:

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

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="-100%"
        android:toYDelta="50%"
        android:duration="3000" />
</set>

答案 2 :(得分:1)

与负值一样简单定义android:fromYDelta

答案 3 :(得分:0)

private fun buildSlideDownAndScaleAnimation(view: View): AnimationSet {
    val animSet = AnimationSet(true)
    animSet.fillAfter = false
    val duration: Long = 1000
    animSet.duration = duration
    animSet.interpolator = AccelerateDecelerateInterpolator()

    val translate = TranslateAnimation(0f, 0f, -1000f, 0f)
    animSet.addAnimation(translate)

    val scale = ScaleAnimation(0f,
                               1f,
                               0f,
                               1f,
                               ScaleAnimation.RELATIVE_TO_SELF,
                               .5f,
                               ScaleAnimation.RELATIVE_TO_SELF,
                               .5f)

    animSet.addAnimation(scale)

    val alphaAnimation = AlphaAnimation(0f, 1f)
    alphaAnimation.startOffset = duration / 3
    animSet.addAnimation(alphaAnimation)

    return animSet
}
相关问题