如何从固定位置上下移动图像,而不是从底部开始?
问题描述:
我目前使用的代码:如何从固定位置上下移动图像,而不是从底部开始?
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)
答
下面是详细代码淡入|渐现出去并且也用于上移|下移
移动式和移动向下的图像查看代码:
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);
感谢,这也帮助,但现在的图像有点太高了,以前如何阻止它?或者,如果你可以在'TranslateAnimation'上解释参数,我可以尝试自己。 –
如果您想停止之前,请更改TranslateAnimation.RELATIVE_TO_SELF,-1.0f);到TranslateAnimation.RELATIVE_TO_SELF,-.0.5f); –
这工作,谢谢。 –