如何更改animateLayoutChanges顺序?

时间:2018-10-16 04:56:16

标签: android android-animation

我在布局中使用了animateLayoutChanges,我有3个孩子,第二个可见性消失了,因此第三个在下面的第一个可见性中。单击第一个孩子时,将第二个可见性更改为可见,反之亦然。

当我看到动画顺序看起来很糟糕时,我希望动画在放映或放下或在隐藏和放上时平行运行。

有gif。 Animation Gif

我想要的是动画,它在隐藏和下拉或显示并上拉时并行运行。

有我的xml

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/space_medium"
android:animateLayoutChanges="true"
android:orientation="vertical">

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/top"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_primary_rounded_top"
    android:paddingLeft="@dimen/space_medium"
    android:paddingTop="@dimen/space_small"
    android:paddingRight="@dimen/space_medium"
    android:paddingBottom="@dimen/space_small">

    <TextView
        android:id="@+id/username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/username"
        android:textColor="@color/white" />

    <com.mikepenz.iconics.view.IconicsImageView
        android:id="@+id/detail"
        android:layout_width="16dp"
        android:layout_height="16dp"
        app:iiv_color="@color/divider"
        app:iiv_icon="@string/gmd_keyboard_arrow_down"
        app:layout_constraintBottom_toBottomOf="@+id/username"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/username" />

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
    android:visibility="gone"
    android:id="@+id/center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/secondaryDarkColor"
    app:layout_constraintTop_toBottomOf="@id/top">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/white"/>

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="@dimen/space_medium"
        android:paddingTop="@dimen/space_small"
        android:paddingRight="@dimen/space_medium"
        android:paddingBottom="@dimen/space_small"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/city"
                android:textColor="@color/white"
                android:gravity="left"
                android:textSize="5pt" />

            <TextView
                android:id="@+id/city"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Jakarta"
                android:textAlignment="textEnd"
                android:textColor="@color/white"
                android:textSize="5pt"
                android:gravity="end" />

        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/divider"
            android:layout_marginTop="@dimen/space_small"
            android:layout_marginBottom="@dimen/space_small"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/status"
                android:textColor="@color/white"
                android:textSize="5pt" />

            <TextView
                android:id="@+id/status"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Started"
                android:textAlignment="textEnd"
                android:textColor="@color/white"
                android:textSize="5pt"
                android:gravity="end" />

        </LinearLayout>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_primary_rounded_bottom"
    android:paddingLeft="@dimen/space_medium"
    android:paddingTop="@dimen/space_small"
    android:paddingRight="@dimen/space_medium"
    android:paddingBottom="@dimen/space_small"
    app:layout_constraintTop_toBottomOf="@+id/center">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="3"
        app:layout_constraintLeft_toLeftOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <com.mikepenz.iconics.view.IconicsImageView
                android:id="@+id/start"
                android:layout_width="24dp"
                android:layout_height="24dp"
                app:iiv_color="@color/white"
                app:iiv_icon="@string/faw_play"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/space_small"
                android:enabled="true"
                android:text="@string/start"
                android:textAlignment="center"
                android:textColor="@color/text_button"
                android:textSize="5pt"
                app:layout_constraintTop_toBottomOf="@+id/start" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <com.mikepenz.iconics.view.IconicsImageView
                android:id="@+id/pause"
                android:layout_width="24dp"
                android:layout_height="24dp"
                app:iiv_color="@color/grey"
                app:iiv_icon="@string/faw_pause"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/space_small"
                android:enabled="false"
                android:text="@string/pause"
                android:textAlignment="center"
                android:textColor="@color/text_button"
                android:textSize="5pt"
                app:layout_constraintTop_toBottomOf="@+id/pause" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <com.mikepenz.iconics.view.IconicsImageView
                android:id="@+id/stop"
                android:layout_width="24dp"
                android:layout_height="24dp"
                app:iiv_color="@color/grey"
                app:iiv_icon="@string/faw_stop"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/space_small"
                android:enabled="false"
                android:text="@string/stop"
                android:textAlignment="center"
                android:textColor="@color/text_button"
                android:textSize="5pt"
                app:layout_constraintTop_toBottomOf="@+id/stop" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

并且有显示隐藏代码

if (detailExpanded) {
    detail.setIcon(
            new IconicsDrawable(getContext())
                    .icon(GoogleMaterial.Icon.gmd_keyboard_arrow_down)
                    .color(getResources().getColor(R.color.divider))
                    .sizeDp(16));
    detailExpanded = false;
    detailGroup.setVisibility(View.GONE);
} else {
    detail.setIcon(
            new IconicsDrawable(getContext())
                    .icon(GoogleMaterial.Icon.gmd_keyboard_arrow_up)
                    .color(getResources().getColor(R.color.divider))
                    .sizeDp(16));
    detailExpanded = true;
    detailGroup.setVisibility(View.VISIBLE);
}

0 个答案:

没有答案