在我的Android应用程序中,我想显示动画以便从其位置弹出视图
更多细节我希望实现这样的目标 -
我对android中的Animation类,Animation Listener和AnimationSet知之甚少。 但仍在寻求实现此功能的指南
你能否建议实现这个目标?
编辑部分 -
主要问题是在将视图移动到顶部后获得正确的视图坐标 并且下一个问题是将该视图从最后位置带到屏幕的中心
答案 0 :(得分:0)
试试这个,
ScaleAnimation animScale = new ScaleAnimation(0, 2, 0, 5);
animScale.setDuration(2000);
AnimationSet animation = new AnimationSet(false);
animation.addAnimation(animScale);
view.startAnimation(animation);
更改ScaleAnimation构造函数中的值以获取所需的输出
答案 1 :(得分:0)
以下代码将有一个动画 - 它将向下移动并以缩放效果进入中间
@Override
public void onClick(final View view) {
TranslateAnimation translateAnimation1 = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT,
0.0f,
TranslateAnimation.RELATIVE_TO_PARENT,
0.8f,
TranslateAnimation.RELATIVE_TO_PARENT,
0.0f,
TranslateAnimation.RELATIVE_TO_PARENT,
0.8f);
translateAnimation1.setDuration(1000);
translateAnimation1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {}
@Override
public void onAnimationRepeat(Animation arg0) {}
@Override
public void onAnimationEnd(Animation arg0) {
TranslateAnimation translateAnimation2 = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT,
0.8f,
TranslateAnimation.RELATIVE_TO_PARENT,
0.5f,
TranslateAnimation.RELATIVE_TO_PARENT,
0.8f,
TranslateAnimation.RELATIVE_TO_PARENT,
0.5f);
translateAnimation2.setDuration(1000);
AnimationSet animationSet = new AnimationSet(false);
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 2.0f,1.0f,2.0f,ScaleAnimation.RELATIVE_TO_SELF ,0.5f,ScaleAnimation.RELATIVE_TO_SELF,0.5f);
scaleAnimation.setDuration(1000);
animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(translateAnimation2);
view.startAnimation(animationSet);
}
});
view.startAnimation(translateAnimation1);
}