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

时间:2017-06-16 17:13:57

标签: android android-animation translate-animation

我目前使用的代码:

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

2 个答案:

答案 0 :(得分:3)

试试这个:

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)

与alphaAnimation结合使用:

DT[, .SD
   ][, V1Val := Value[V1 == 1], V4
   ][order(-V1Val, V4)
   ][, V4 := factor(V4, levels=unique(V4))
   ][, V1 := factor(V1)
   ][, ggplot(.SD, aes(x=V4, y=Value, fill=V1))
   + geom_bar(stat="identity", position=position_dodge())
   + theme(axis.text.x=element_text(angle=45, hjust=1),
           axis.line.x=element_line(),
           axis.line.y=element_line(),
           panel.background=element_blank())
   ]       

答案 1 :(得分:2)

以下是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);