幻灯片动画无法执行

时间:2017-11-12 17:37:29

标签: android android-animation

我尝试在Android应用中学习动画。我为此制作了我的测试应用程序。 我练习本教程github tut。我选择了标记为“编程”的方式。这几行代码很简单,但它不会改变活动之间的动画。我克隆了rep,并在tut的应用程序中制作了一个幻灯片动画。

我的代码是2个类和2个XML文件:

public class MainActivity extends AppCompatActivity {


Button greenButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setupWindowAnimations();
    greenButton= findViewById(R.id.button4);
    greenButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("Image", "Clicked");


            Intent i = new Intent(MainActivity.this, Green.class);
            startActivity(i);
        }
    });

}

private void setupWindowAnimations() {
    Slide slide = new Slide();
    slide.setDuration(100000);
    getWindow().setExitTransition(slide);
}}

第二课:

public class Green extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_green);
    setupWindowAnimations();
}
private void setupWindowAnimations() {
    Fade fade = new Fade();
    fade.setDuration(100000);
    getWindow().setEnterTransition(fade);
}}

1st XML

<LinearLayout android:id="@+id/sample_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:gravity="center_vertical"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">


    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="84dp"
        android:layout_weight="1"
        android:background="@android:color/holo_green_light"
        android:text="Button 1"
        android:theme="@android:style/Widget.Material.Light.ActionButton" />

    <Button
        android:id="@+id/button8"
        android:layout_width="match_parent"
        android:layout_height="99dp"
        android:layout_marginVertical="20dp"
        android:layout_weight="1"
        android:background="@android:color/holo_orange_dark"
        android:text="Button"
        android:theme="@android:style/Widget.Material.Light.ActionButton" />

    <Button
        android:id="@+id/button9"
        android:layout_width="match_parent"
        android:layout_height="104dp"
        android:layout_weight="1"
        android:background="@android:color/holo_purple"
        android:text="Button"
        android:theme="@android:style/Widget.Material.Light.ActionButton" />

    <Button
        android:id="@+id/button10"
        android:layout_width="match_parent"
        android:layout_height="138dp"
        android:layout_marginVertical="20dp"
        android:layout_weight="1"
        android:background="?android:attr/textColorLinkInverse"
        android:text="Button"
        android:theme="@android:style/Widget.Material.Light.ActionButton" />
</LinearLayout>

第二个XML:

<LinearLayout android:id="@+id/sample_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:gravity="center_vertical"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

<Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="113dp"
    android:layout_marginBottom="200dp"
    android:layout_marginTop="20dp"
    android:text="Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="118dp"
    android:text="Button" />

有没有人有任何想法?

0 个答案:

没有答案