如何从固定位置上下移动图像,而不是从底部开始?

How to move image up and down from a fixed location, rather than starting from the bottom?

我目前使用的代码:

    TranslateAnimation mAnimation = new TranslateAnimation(
            TranslateAnimation.ABSOLUTE, 0f,
            TranslateAnimation.ABSOLUTE, 0f,
            TranslateAnimation.RELATIVE_TO_PARENT, 0f,
            TranslateAnimation.RELATIVE_TO_PARENT, 1.0f);
    mAnimation.setDuration(2000);
    mAnimation.setRepeatCount(-1);
    mAnimation.setRepeatMode(Animation.REVERSE);
    mAnimation.setInterpolator(new LinearInterpolator());
    imageView.setAnimation(mAnimation);

这里是result.(画质无视,我改)

我将图像放置在水平居中,与浮动操作按钮垂直对齐。我希望它从那里开始。

此外,我还可以选择创建淡入淡出效果 AlphaAnimation。我如何同步它们?

AlphaAnimation 代码:

AlphaAnimation blinkAnimation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
    blinkAnimation.setDuration(1000); // duration - half a second
    blinkAnimation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    blinkAnimation.setRepeatCount(5000); // Repeat animation infinitely
    blinkAnimation.setRepeatMode(Animation.REVERSE);

试试这个:

TranslateAnimation mAnimation = new TranslateAnimation(
            TranslateAnimation.RELATIVE_TO_SELF, 0f,
            TranslateAnimation.RELATIVE_TO_SELF, 0f,
            TranslateAnimation.RELATIVE_TO_SELF, 0f,
            TranslateAnimation.RELATIVE_TO_SELF, -1.0f);
//Less up :     TranslateAnimation.RELATIVE_TO_SELF, -0.5f);

与 alphaAnimation 结合:

AlphaAnimation blinkAnimation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
    blinkAnimation.setDuration(1000); // duration - half a second
    blinkAnimation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    blinkAnimation.setRepeatCount(5000); // Repeat animation infinitely
    blinkAnimation.setRepeatMode(Animation.REVERSE);

AnimationSet set = new AnimationSet(true);
set.addAnimation(trAnimation);
set.addAnimation(mAnimation);
imageView.startAnimation(set)

这里是 Fade-In|Fade-Out 和 Move-Up|Move-Down 的详细代码

上移和下移图像查看代码:

    TranslateAnimation anim = new TranslateAnimation(
            TranslateAnimation.RELATIVE_TO_SELF, 0f,
            TranslateAnimation.RELATIVE_TO_SELF, 0f,
            TranslateAnimation.RELATIVE_TO_SELF, 0f,
            TranslateAnimation.RELATIVE_TO_SELF, -1.0f); // this is distance of top and bottom form current positiong

           anim.setDuration(2000);
           anim.setRepeatCount(3);
           anim.setRepeatMode(Animation.REVERSE);  
           downloadIV.startAnimation(anim);

淡入和淡出:

   AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f);
    anim.setDuration(500);
    anim.setRepeatCount(4);
    anim.setRepeatMode(Animation.REVERSE);

    //anim.setFillAfter(true);
   downloadIV.startAnimation(anim);