我的ImageButton正在水平移动。但我想要横向和纵向移动。 然后重复。
move.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>
如果我在move.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);
答案 0 :(得分:0)
如果您以编程方式创建动画实例,请执行以下操作:
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
然后您可以将计数器设置为重复多次相同的动画 如你所愿:
animation.setRepeatCount(10);