Mat*_*hew 19 animation android views
有没有办法同时为多个视图制作动画?
我想要做的是翻译动画:
我有5个TextView和4个彩色条带(带有背景的普通RelativeLayouts).在动画开始时,stips与TextViews在水平行中堆叠.最后,我想要在条带之间堆叠所有TextView:

这是一个非常简单的绘图,但它展示了我想要做的事情.有没有办法用动画做这个,或者我必须使用画布动画.
Pra*_*eep 55
您可以使用ObjectAnimator为多视图设置动画,如下所示:
ArrayList<ObjectAnimator> arrayListObjectAnimators = new ArrayList<ObjectAnimator>(); //ArrayList of ObjectAnimators
ObjectAnimator animY = ObjectAnimator.ofFloat(view, "y", 100f);
arrayListObjectAnimators.add(animY);
ObjectAnimator animX = ObjectAnimator.ofFloat(view, "x", 0f);
arrayListObjectAnimators.add(animX);
...
ObjectAnimator[] objectAnimators = arrayListObjectAnimators.toArray(new ObjectAnimator[arrayListObjectAnimators.size()]);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(objectAnimators);
animSetXY.setDuration(1000);//1sec
animSetXY.start();
Run Code Online (Sandbox Code Playgroud)
您可以使用动画集
AnimatorSet decSet2 = new AnimatorSet();
decSet2.playTogether(
ObjectAnimator.ofFloat(view, "x",dX),
ObjectAnimator.ofFloat(view, "y",dY),
ObjectAnimator.ofFloat(mTextCancel, "x",dX),
ObjectAnimator.ofFloat(mTextCancel, "y", dY),
ObjectAnimator.ofArgb(mBtnOne, "visibility", View.VISIBLE, View.GONE),
);
decSet2.setDuration(0);
decSet2.start();
Run Code Online (Sandbox Code Playgroud)
创建动画对象,然后同时startAnimation在所有视图上共同使用。所以会是这样的:
TranslateAnimation anim1;
TranslateAnimation anim2;
TranslateAnimation anim3;
// Setup the animation objects
public void startAnimations()
{
//... collect view objects
view1.startAnimation(anim1);
view2.startAnimation(anim2);
view3.startAnimation(anim3);
}
Run Code Online (Sandbox Code Playgroud)
只需注意一下,一次执行的动画越多,它就会变得越慢。
| 归档时间: |
|
| 查看次数: |
27662 次 |
| 最近记录: |