[英]How to use Translate Animation
How do I make Relative Layout get smaller from the bottom to top animation and stop at height of 150dp using a Translation Animation? 如何使用“平移动画”使“相对布局”从底部动画到顶部变小并停在150dp的高度? Here is what I got.
这就是我得到的。
TranslateAnimation translation = new TranslateAnimation(1.0f, 1.0f, relativeLayout.getHeight(), 0.0f);
translation.setDuration(2000);
relativeLayout.startAnimation(translation);
As i understood, you need to translate your layout from bottom to top or top to bottom. 据我了解,您需要从底部到顶部或从顶部到底部转换布局。 Try like this
这样尝试
Bottom to Top 从下到上
public void SlideToAbove() {
Animation slide = null;
slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, -5.0f);
slide.setDuration(400);
slide.setFillAfter(true);
slide.setFillEnabled(true);
rl_layout.startAnimation(slide);
slide.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
rl_layout.clearAnimation();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
rl_layout.getWidth(), rl_layout.getHeight());
lp.setMargins(0, 0, 0, 0);
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
rl_layout.setLayoutParams(lp);
}
});
}
Top to Bottom 从上到下
public void SlideToDown() {
Animation slide = null;
slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, 5.2f);
slide.setDuration(400);
slide.setFillAfter(true);
slide.setFillEnabled(true);
rl_layout.startAnimation(slide);
slide.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
rl_layout.clearAnimation();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
rl_layout.getWidth(), rl_layout.getHeight());
lp.setMargins(0, rl_layout.getWidth(), 0, 0);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rl_layout.setLayoutParams(lp);
}
});
}
Refer this link also 另请参阅此链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.