這就是你給動畫/過渡到佈局,觀點或部件
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" />
@pleaseMOM例如:.x(-5000).y(0)我是對嗎? – Ataberk
@pleaseMOM無法使用。我認爲這不符合邏輯 – Ataberk
你想達到什麼目的?我有幾個動畫片段 – MaggotSauceYumYum