0

私は基本的にビデオゲーム用の D-Pad をプログラミングしています。 ImageView を一定の X または Y で移動させ、ボタンを離した後もその位置を維持する方法を見つけようとしています。

私が具体的に何をしているのかについての助けや質問は大歓迎です。

4

3 に答える 3

0

使用できますObjectAnimator.ofFloat(Object target, String property, float values...)

LinearInterpomatorアニメーションの進行が一定になるように設定します。

例 :

ObjectAnimator animator = ObjectAnimator.ofFloat(myImage, "X", 0f, 150f);

補間器を設定: animator.setInterpolator(new LinearInterpolator());

ミリ秒単位の期間: animator.setDuration(5000); //5 seconds

次に、それを開始します。

イメージを X 軸の 0 から 150 に移動します。String プロパティは、新しい座標値を適用するオブジェクト プロパティを参照します。

お役に立てば幸いです。

注 : from と to の値を変更して、from の値が画像の実際の位置に対応し、目的の座標が実際に新しい位置にあるようにすることができます。

KitKat TransitionManaqgerなどの他のソリューションがありますが、KitKat の前にデバイスをターゲットにしたい場合は、ObjectAnimator を使用できます。

于 2016-01-06T09:57:53.170 に答える
0

slideanimation.xml を作成する

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">

<translate
    android:duration="1500"
    android:fromXDelta="-100%"
    android:fromYDelta="0%"
    android:repeatMode="reverse"
    android:toXDelta="0%"
    android:toYDelta="0%" />

</set>

コード内

image = (ImageView) findViewById(R.id.imageLady);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.slide_right);
image.startAnimation(animation);
于 2016-01-06T09:58:13.050 に答える
0

ObjectAnimator を使用できます。ビュー (myView) を 5 ピクセル上にスライドするには:

ObjectAnimator animator = ObjectAnimator.ofInt(myView, "x", myView.getX()+5);
animator.start();
于 2016-01-06T09:50:35.007 に答える