2015-11-22 32 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

相关问题