2

アプリケーションで画像のアニメーションを作成しました。画像は、画面の中央から左上隅まで表示され始めます。ここで、画像がすべてのデバイスの左上隅にある正しい位置に配置されるようにする必要があります。現在、左上隅のさまざまなデバイスのさまざまな位置に配置されています。どうすれば修正できますか?私は次のように私のコードを持っています:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">
    <translate
        android:fromXDelta="0%p"
        android:toXDelta="-36%p"
        android:fromYDelta="0%p"
        android:toYDelta="-30.9%p"
        android:duration="500"
        android:fillAfter="true" />
</set>

誰でも助けてください。

4

1 に答える 1

0

これでかなり良い結果が得られたので、これがあなたや誰かに役立つことを願っています. 考え方は単純です。

アニメートしたいものをxmlを介して最終的な位置に配置し、そのfrom値を任意のfloat値および0として使用TranslateAnimationおよび設定します。このようにして、ウィジェット/ビューがアニメーション化し、xml で配置した場所に静止します。

TextView画面の外側から xml で指定された位置にアニメーション化する小さな例。

//This is just for getting the from value, from where animation starts.
WindowManager wm = (WindowManager) mContext
        .getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int width = display.getWidth();

Animation  moveRighttoLeft = new TranslateAnimation(width, 0, 0, 0);
moveRighttoLeft.setDuration(700);

AnimationSet animation = new AnimationSet(false);
animation.addAnimation(moveRighttoLeft);
myTextView.setAnimation(animation);

ここにxmlがあります

<TextView
    android:id="@+id/mytextview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="This is a Text View"
    android:layout_marginLeft="30dp"/>
于 2012-06-27T19:07:16.730 に答える