android path怎么动画
1个回答
展开全部
Path规划动画轨迹
public void testPathAnimator(){
final FrameLayout l = (FrameLayout) findViewById(R.id.root_view);
final ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.dot);
FrameLayout.LayoutParams param = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
l.addView(imageView, param);
Path path = new Path();
path.moveTo(200, 200);
path.quadTo(800, 200, 800, 800);
PathInterpolator pathInterpolator = new PathInterpolator(0.33f,0f,0.12f,1f);
AnimatorSet animSet = new AnimatorSet();
animSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
l.removeView(imageView);
}
@Override
public void onAnimationCancel(Animator animation) {
l.removeView(imageView);
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
ObjectAnimator scalex = ObjectAnimator.ofFloat(imageView, View.SCALE_X, 1.0f, 0.3f);
ObjectAnimator scaley = ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 1.0f, 0.3f);
ObjectAnimator traslateAnimator = ObjectAnimator.ofFloat(imageView, "x", "y", path);
animSet.playTogether(scalex, scaley, traslateAnimator);
animSet.setInterpolator(pathInterpolator);
animSet.setDuration(1500);
animSet.start();
}
}
public void testPathAnimator(){
final FrameLayout l = (FrameLayout) findViewById(R.id.root_view);
final ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.dot);
FrameLayout.LayoutParams param = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
l.addView(imageView, param);
Path path = new Path();
path.moveTo(200, 200);
path.quadTo(800, 200, 800, 800);
PathInterpolator pathInterpolator = new PathInterpolator(0.33f,0f,0.12f,1f);
AnimatorSet animSet = new AnimatorSet();
animSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
l.removeView(imageView);
}
@Override
public void onAnimationCancel(Animator animation) {
l.removeView(imageView);
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
ObjectAnimator scalex = ObjectAnimator.ofFloat(imageView, View.SCALE_X, 1.0f, 0.3f);
ObjectAnimator scaley = ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 1.0f, 0.3f);
ObjectAnimator traslateAnimator = ObjectAnimator.ofFloat(imageView, "x", "y", path);
animSet.playTogether(scalex, scaley, traslateAnimator);
animSet.setInterpolator(pathInterpolator);
animSet.setDuration(1500);
animSet.start();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询