2017-01-23 122 views
0

我的ImageButton正在水平移動。但我想移動水平和垂直。 然後重複。動畫:水平和垂直移動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的一些代碼

​​

回答

0

如果要創建動畫的實例程序是這樣的:

Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move); 

那麼你可以設置櫃檯重複相同動畫多次 只要你想:

animation.setRepeatCount(10);