2017-01-23 28 views
0

My ImageButtonが正しく水平に移動しています。しかし、私は水平と垂直の両方の動きが欲しい。 その後、繰り返します。私はmove.xmlで、この行を追加する場合アニメーション: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> 

android:toYDelta="70%p" 

これは、斜めに移動します。しかし、最初に水平方向に移動してから垂直方向にも移動します。

のいくつかのコードMainActivity.java

​​

答えて

0

あなたがプログラムによってこのようにアニメーションのインスタンスを作成する場合:

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

、あなたは同じことを繰り返すようにカウンタを設定することができます何度もアニメーションを何度もやります。

animation.setRepeatCount(10); 
関連する問題