2015-11-22 35 views
1

我有這樣一個佈局:有什麼方法可以扭轉這個動畫?

app design example

我這個動畫按鈕linearlayouts使用此代碼:

public void animation(){ 
ust.animate().x(0).y(-5000).setDuration(500).start(); //My linear layout in the top of screen.  
alt.animate().x(0).y(4000).setDuration(500).start(); //My linear layout in the bottom of screen. 
    } 

我要扭轉這種動畫。

我試過這種方式,但我的屏幕底部的線性佈局,到頂部。

嘗試這種方式:

public void animation(){ 
ust.animate().x(0).y(0).setDuration(500).start(); //My relative layout in the top of screen.  
alt.animate().x(0).y(0).setDuration(500).start(); //My relative layout in the bottom of screen. 
    } 

當我想嘗試這樣的事:

public void animation(){ 
ust.animate().x(0).y(0).setDuration(500).start(); //My relative layout in the top of screen.  
alt.animate().x(0).y(500).setDuration(500).start(); //My relative layout in the bottom of screen. 
    } 

「ALT」視圖不來在所有設備屏幕的底部。

我想扭轉此動畫。我怎樣才能做到這一點?

+0

@pleaseMOM例如:.x(-5000).y(0)我是對嗎? – Ataberk

+0

@pleaseMOM無法使用。我認爲這不符合邏輯 – Ataberk

+0

你想達到什麼目的?我有幾個動畫片段 – MaggotSauceYumYum

回答

1

動畫之前,請記住您的意見Y座標,然後重新倒車時的y位置:

float ustY; 
float altY; 
public void animation(){ 
    ustY=ust.getY(); 
    ust.animate().x(0).y(-5000).setDuration(500).start(); //My linear layout in the top of screen.  
    altY=alt.getY(); 
    alt.animate().x(0).y(4000).setDuration(500).start(); //My linear layout in the bottom of screen. 
} 
public void reverseAnimation(){ 
    ust.animate().x(0).y(ustY).setDuration(500).start(); //My linear layout in the top of screen.  
    alt.animate().x(0).y(altY).setDuration(500).start(); //My linear layout in the bottom of screen. 
} 
+0

非常感謝!它的工作原理:D我這樣想,但沒有活過來。 – Ataberk

0

假設視圖原本沒x或y的偏移量和通過反向你指恢復視圖到原來的位置,呼叫yourView.animate()。Y(0).setDuration(500)。開始()

+0

已更新第一個主題。這也不工作 – Ataberk

1

這就是你給動畫/過渡到佈局,觀點或部件

public class MainActivity extends Activity { 
Animation RL1, RL2, LR1, LR2, fadein, fadeout; 
private View view1; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    findViewById(R.id.film1).setVisibility(View.GONE); 
    // Define all animations 
    new AnimationUtils(); 

    RL1 = AnimationUtils.loadAnimation(getApplicationContext(), 
      R.anim.slide_right_to_left_1); 
    RL2 = AnimationUtils.loadAnimation(getApplicationContext(), 
      R.anim.slide_right_to_left_2); 

    LR1 = AnimationUtils.loadAnimation(getApplicationContext(), 
      R.anim.slide_left_to_right_2); 
    LR2 = AnimationUtils.loadAnimation(getApplicationContext(), 
      R.anim.slide_left_to_right_1); 

    fadein = AnimationUtils.loadAnimation(getApplicationContext(), 
      R.anim.fadeout); 
    fadeout = AnimationUtils.loadAnimation(getApplicationContext(), 
      R.anim.fix); 
} 

// **// 

public void show(View view) { 
    findViewById(R.id.film1).setVisibility(View.VISIBLE); 
    view1 = (View) findViewById(R.id.film1); 
    view1.setAnimation(LR1); 
    view1.setAnimation(LR2); 
} 

// 

}

建立在「動畫」文件夾這些XML文件,這些包含您的動畫。

slide_left_to_right_1.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 
<translate 
    android:duration="600" 
    android:fromXDelta="-100%" 
    android:toXDelta="0%" > 
</translate> 
</set> 

slide_left_to_right_2.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 
<translate 
    android:duration="600" 
    android:fromXDelta="0%" 
    android:toXDelta="100%" > 
</translate> 
</set> 

slide_right_to_left_1.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 
<translate 
    android:duration="600" 
    android:fromXDelta="100%" 
    android:toXDelta="0%" > 
</translate> 
</set> 

slide_right_to_left_2.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 
<translate 
    android:duration="600" 
    android:fromXDelta="0%" 
    android:toXDelta="-100%" > 
</translate> 
</set> 

fadeout.xml

<?xml version="1.0" encoding="utf-8"?> 
<alpha xmlns:android="http://schemas.android.com/apk/res/android" 
android:duration="800" 
android:fromAlpha="0.0" 
android:interpolator="@android:anim/accelerate_interpolator" 
android:toAlpha="1.0" /> 

fix.xml

<?xml version="1.0" encoding="utf-8"?> 
<alpha xmlns:android="http://schemas.android.com/apk/res/android" 
android:duration="800" 
android:fromAlpha="1.0" 
android:interpolator="@android:anim/accelerate_interpolator" 
android:toAlpha="0.0" /> 
+0

我有linearlayout按鈕。當我使用ust.setAnimation(淡出); (使用linearlayout)按鈕不移動 – Ataberk

+0

給你的按鈕這個ID「film1」 – MaggotSauceYumYum

+0

仍然我的按鈕可點擊影響呆在那裏或移動? – Ataberk

相關問題