我的图像按钮正在正确水平移动。但是我想同时移动水平和垂直。然后重复。
移动.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillBefore="true"
android:repeatMode="reset">
<translate
android:fromXDelta="0%p"
android:toXDelta="70%p"
android:duration="2000" />
</set>
hand_motion.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aa000000"
android:id="@+id/VHandLevel">
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/ibtnHandLevel"
android:background="@drawable/hand1"
android:layout_marginTop="80dp" />
</RelativeLayout>
如果我在移动中添加此行.xml:
android:toYDelta="70%p"
它将沿对角线移动。但我想先水平移动,然后垂直也会重复。
MainActivity的一些代码.java
ImageButton iBtnHelp = (ImageButton)dialog.findViewById(R.id.ibtnHandLevel);
Animation animation1 =
AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
animation1.setRepeatCount(20);
iBtnHelp.startAnimation(animation1);
如果您以编程方式创建动画的实例,如下所示:
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
然后,您可以将计数器设置为多次重复相同的动画如你所愿:
animation.setRepeatCount(10);