ConstraintSet动画幻灯片放入ImageViews

时间:2018-06-10 03:49:52

标签: android animation kotlin

ConstraintSet新手。尝试在启动画面上为两个ImageView设置动画。我希望prefix_text从左边距向右滑动,而suffix_text从右边距向左滑动。但没有任何反应。我不知道自己错过了什么。

class SplashActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_splash_start)
        addAnimationOperations()
    }

    private fun addAnimationOperations() {

        val constraint1 = ConstraintSet()
        constraint1.clone(root)
        val constraint2 = ConstraintSet()
        constraint2.clone(this, R.layout.activity_splash_done)

        TransitionManager.beginDelayedTransition(root)
        constraint2.applyTo(root)
    }
}

activity_splash_start.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#333">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/frameLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <ImageView
            android:id="@+id/runners"
            android:layout_width="200dp"
            android:layout_height="0dp"
            android:layout_marginTop="8dp"
            android:contentDescription="@string/whatever"
            app:layout_constraintDimensionRatio="1024:940"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/logo_runners" />

        <android.support.constraint.ConstraintLayout
            android:id="@+id/text_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/runners">

            <ImageView
                android:id="@+id/prefix_text"
                android:layout_width="0dp"
                android:layout_height="30dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintDimensionRatio="672:215"
                app:layout_constraintEnd_toStartOf="parent"
                app:srcCompat="@drawable/logo_name" />

            <ImageView
                android:id="@+id/suffix_text"
                android:layout_width="0dp"
                android:layout_height="30dp"
                app:layout_constraintDimensionRatio="352:215"
                app:layout_constraintStart_toEndOf="parent"
                app:srcCompat="@drawable/logo_dot_club" />
        </android.support.constraint.ConstraintLayout>

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

activity_splash_done.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#333">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/frameLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <ImageView
            android:id="@+id/runners"
            android:layout_width="200dp"
            android:layout_height="0dp"
            android:layout_marginTop="8dp"
            android:contentDescription="@string/whatever"
            app:layout_constraintDimensionRatio="1024:940"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/logo_runners" />

        <android.support.constraint.ConstraintLayout
            android:id="@+id/text_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/runners">

            <ImageView
                android:id="@+id/prefix_text"
                android:layout_width="0dp"
                android:layout_height="30dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintDimensionRatio="672:215"
                app:layout_constraintStart_toStartOf="parent"
                app:srcCompat="@drawable/logo_name" />

            <ImageView
                android:id="@+id/suffix_text"
                android:layout_width="0dp"
                android:layout_height="30dp"
                app:layout_constraintDimensionRatio="352:215"
                app:layout_constraintStart_toEndOf="@+id/werun_text"
                app:srcCompat="@drawable/logo_dot_club" />
        </android.support.constraint.ConstraintLayout>

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

0 个答案:

没有答案