24

私は通過しました

TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

しかし、それでもどのように機能するかについて混乱していますTranslate animation

誰かがそれがどのように機能するか説明できますか?私は言うドキュメントを読みました

fromXDelta  Change in X coordinate to apply at the start of the animation
toXDelta    Change in X coordinate to apply at the end of the animation
fromYDelta  Change in Y coordinate to apply at the start of the animation
toYDelta    Change in Y coordinate to apply at the end of the animation 

しかし、それがどのように機能するかはまだ私にはわかりません。

編集:私には子供がいないButtonとがあります。LinearLayoutをクリックすると、Buttonを動的に生成しTextView、アニメーション化してTextViewに表示されますLinearLayout。の数はTextView、ボタンのクリック数によって異なります。

4

2 に答える 2

27

私の知る限り、これの間には相対的なつながりがあります。

つまり、非表示のテキストビューを画面の右側から画面の左側に変換する場合、ボタンをクリックすると、実際には X 方向 (画面の右側) の 100% から X の 0%に変換する必要があります。・方向(画面左側)。

この時点では、Y 方向をまったく変更する必要はありません。したがって、両方のオプションで 0% になります。最終的には、次のようになります。

fromXDelta 100%

toXDelta 0%

fromYDelta 0%

toYDelta 0%

要件に応じて、このパーセンテージを 0 から 100 の間で設定することにより、コンポーネントの表示を制限できます。

同様に、コンポーネントを Y 方向にも変換する必要がある場合は、0% を他の値に変更する必要があります。

願っています、今あなたには明らかです。

編集 :

あなたの要件では、ボタン1のonclickをオーバーライドする必要があり、そこでボタン2の可視性と翻訳を制御できます。

res の anim フォルダーにアニメーション ファイルを作成します。

translate_button.xml:

<?xml version="1.0" encoding="utf-8"?>
<!-- translating button from right to left -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:fromXDelta="100%" android:toXDelta="0%"
        android:fromYDelta="0%" android:toYDelta="0%"
        android:duration="900"
    />
</set>

今、あなたの活動ファイルで、

...

// ll  is linear layout containing button_2
//counter is used to manage visibility of button_2 on click of button_1,i.e.1st click-button_2 would be visible,on 2nd click on button_1,it would be invisible.

//you can change behavior as per your need

button_2.setVisibility(View.GONE);
button_1.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        if(counter<1)
        {
            counter++;                  
            button_2.setVisibility(View.VISIBLE);
            Animation anim=AnimationUtils.loadAnimation(context, R.anim.translate_button);
            button_2.startAnimation(anim);
        }
        else
        {
            counter=0;
            button_2.setVisibility(View.GONE);
        }
    }
});
ll.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        if(counter==1)
        {
            counter=0;
            button_2.setVisibility(View.GONE);
        }
    }
});

...
于 2012-07-16T12:20:13.170 に答える
2

TranslateAnimation を使用すると、オブジェクトを制御するアニメーションを作成できます。

TranslateAnimation を使用すると、オブジェクトの位置を制御できます。X 座標と Y 座標を表すこの 4 つのパラメーターを渡します。

例では、オブジェクトをに移動したい場合、次のようにします: TranslateAnimation(0.0f, 1.0f, 0.0f, 0.0f)

(または , をAnimation.ABSOLUTE使用Animation.RELATIVE_TO_SELF)

簡単な「LeftToRight」アニメーション移動を行っているため、現在は X 座標のみを使用します。

Change in X coordinate to apply at the start of the animation
toXDelta (0.0f)    

Change in X coordinate to apply at the end of the animation (1.0f)

=右に 1

多分http://en.wikipedia.org/wiki/Coordinate_systemを見てください

于 2012-07-16T12:20:40.197 に答える