使用ConstraintSet的ConstraintLayout动画不适用于ScrollView

时间:2019-03-01 05:45:02

标签: android android-animation android-constraintlayout constraintset

我有两个带有ConstraintLayout的布局,它有一个子NestedScrollview,而NestedScrollview又有一个子ConstraintLayout作为容器,而不是其他视图。我想使用ConstraintSet设置两个布局的动画,但是不幸的是,这不起作用。另一方面,如果我删除NestedScrollview和根ConstraintLayout,则它可以正常工作。我想用NestedScrollview或Scroll view实现此任务吗?提前致谢。 这是我的代码

  

activity_login.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_lay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:isScrollContainer="true"
    android:orientation="vertical"
    tools:context=".activity.LoginActivity">

    <!-- Login progress -->
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="8dp">
        <!-- Login progress -->
        <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_lay_la"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true"
            android:gravity="center"
            android:orientation="vertical"
            tools:context=".activity.LoginActivity">

            <ImageView
                android:id="@+id/iv_login_back"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/nature" />

            <ProgressBar
                android:id="@+id/pb_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/tv_login_heading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:gravity="center"
                android:paddingStart="@dimen/fab_margin"
                android:paddingTop="@dimen/small_padding"
                android:paddingEnd="@dimen/fab_margin"
                android:paddingBottom="@dimen/small_padding"
                android:text="Login Heading"
                android:textColor="@color/white"
                android:textSize="20sp"
                android:textStyle="bold"
                app:layout_constraintBottom_toTopOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />

            <Button
                android:id="@+id/btn_sign_in_la"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_size"
                android:layout_gravity="center_horizontal"
                android:layout_marginStart="@dimen/fab_margin"
                android:layout_marginTop="32dp"
                android:layout_marginEnd="@dimen/fab_margin"
                android:layout_marginBottom="8dp"
                android:background="@drawable/login_btn_back"
                android:paddingStart="@dimen/button_padding"
                android:paddingTop="@dimen/normal_padding"
                android:paddingEnd="@dimen/button_padding"
                android:paddingBottom="@dimen/normal_padding"
                android:text="@string/sign_in"
                android:textAllCaps="false"
                android:textColor="@color/primaryDark"
                android:textStyle="bold"
                app:layout_constraintBottom_toBottomOf="@+id/iv_login_back"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/et_password_la"
                app:layout_constraintVertical_bias="0.04000002" />

            <TextView
                android:id="@+id/tv_heading_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:gravity="center"
                android:paddingStart="@dimen/big_margin"
                android:paddingEnd="@dimen/big_margin"
                android:text="Login with Saini Communication and get more offers!"
                android:textColor="@color/white"
                android:textSize="30sp"
                app:layout_constraintBottom_toTopOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />

            <EditText
                android:id="@+id/et_email_or_phone"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/fab_margin"
                android:layout_marginTop="@dimen/big_margin"
                android:layout_marginEnd="@dimen/fab_margin"
                android:background="@drawable/et_back"
                android:drawableStart="@drawable/ic_phone_iphone_black_24dp"
                android:drawablePadding="@dimen/fab_margin"
                android:ems="10"
                android:hint="@string/mobile"
                android:inputType="phone"
                android:paddingStart="@dimen/normal_padding"
                android:paddingTop="@dimen/medium_padding"
                android:paddingEnd="@dimen/normal_padding"
                android:paddingBottom="@dimen/medium_padding"
                android:textColor="@color/white"
                android:textColorHint="@color/whiteLight"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="parent" />

            <EditText
                android:id="@+id/et_password_la"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/fab_margin"
                android:layout_marginTop="@dimen/big_margin"
                android:layout_marginEnd="@dimen/fab_margin"
                android:background="@drawable/et_back"
                android:drawableStart="@drawable/ic_lock_black_24dp"
                android:drawablePadding="@dimen/fab_margin"
                android:ems="10"
                android:hint="@string/prompt_password"
                android:inputType="textPassword"
                android:paddingStart="@dimen/normal_padding"
                android:paddingTop="@dimen/medium_padding"
                android:paddingEnd="@dimen/normal_padding"
                android:paddingBottom="@dimen/medium_padding"
                android:textColor="@color/white"
                android:textColorHint="@color/whiteLight"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/et_email_or_phone" />

        </android.support.constraint.ConstraintLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.constraint.ConstraintLayout>
  

activity_login_detial.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_lay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".activity.LoginActivity">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="8dp">
        <!-- Login progress -->
        <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_lay_la"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true"
            android:gravity="center"
            android:orientation="vertical"
            tools:context=".activity.LoginActivity">

            <ImageView
                android:id="@+id/iv_login_back"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:scaleType="centerCrop"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.26999998"
                app:srcCompat="@drawable/nature" />

            <ProgressBar
                android:id="@+id/pb_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/tv_login_heading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:gravity="center"
                android:paddingStart="@dimen/fab_margin"
                android:paddingTop="@dimen/small_padding"
                android:paddingEnd="@dimen/fab_margin"
                android:paddingBottom="@dimen/small_padding"
                android:text="Login Heading"
                android:textColor="@color/white"
                android:textSize="20sp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@+id/btn_sign_in_la"
                android:layout_width="0dp"
                android:layout_height="@dimen/button_size"
                android:layout_gravity="center_horizontal"
                android:layout_marginStart="@dimen/fab_margin"
                android:layout_marginTop="32dp"
                android:layout_marginEnd="@dimen/fab_margin"
                android:layout_marginBottom="8dp"
                android:background="@drawable/login_btn_back"
                android:paddingStart="@dimen/button_padding"
                android:paddingTop="@dimen/normal_padding"
                android:paddingEnd="@dimen/button_padding"
                android:paddingBottom="@dimen/normal_padding"
                android:text="@string/sign_in"
                android:textAllCaps="false"
                android:textColor="@color/primaryDark"
                android:textStyle="bold"
                app:layout_constraintBottom_toBottomOf="@+id/iv_login_back"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/et_password_la"
                app:layout_constraintVertical_bias="0.04000002" />

            <TextView
                android:id="@+id/tv_heading_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:gravity="center"
                android:paddingStart="@dimen/big_margin"
                android:paddingEnd="@dimen/big_margin"
                android:text="Login with Saini Communication and get more offers!"
                android:textColor="@color/white"
                android:textSize="30sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/tv_login_heading" />

            <EditText
                android:id="@+id/et_email_or_phone"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/fab_margin"
                android:layout_marginTop="@dimen/big_margin"
                android:layout_marginEnd="@dimen/fab_margin"
                android:background="@drawable/et_back"
                android:drawableStart="@drawable/ic_phone_iphone_black_24dp"
                android:drawablePadding="@dimen/fab_margin"
                android:ems="10"
                android:hint="@string/mobile"
                android:inputType="phone"
                android:paddingStart="@dimen/normal_padding"
                android:paddingTop="@dimen/medium_padding"
                android:paddingEnd="@dimen/normal_padding"
                android:paddingBottom="@dimen/medium_padding"
                android:textColor="@color/white"
                android:textColorHint="@color/whiteLight"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/tv_heading_login" />

            <EditText
                android:id="@+id/et_password_la"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/fab_margin"
                android:layout_marginTop="@dimen/big_margin"
                android:layout_marginEnd="@dimen/fab_margin"
                android:background="@drawable/et_back"
                android:drawableStart="@drawable/ic_lock_black_24dp"
                android:drawablePadding="@dimen/fab_margin"
                android:ems="10"
                android:hint="@string/prompt_password"
                android:inputType="textPassword"
                android:paddingStart="@dimen/normal_padding"
                android:paddingTop="@dimen/medium_padding"
                android:paddingEnd="@dimen/normal_padding"
                android:paddingBottom="@dimen/medium_padding"
                android:textColor="@color/white"
                android:textColorHint="@color/whiteLight"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/et_email_or_phone" />
        </android.support.constraint.ConstraintLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.constraint.ConstraintLayout>
  

LoginActivity.java

@BindView(R.id.root_lay_la)
ConstraintLayout animLay;
public void show(){
    show=true;
    ConstraintSet constraintSet=new ConstraintSet();
    constraintSet.clone(this,R.layout.activity_login_detail);
    android.support.transition.Transition transition=new android.support.transition.ChangeBounds();
    AnticipateOvershootInterpolator interpolator=new AnticipateOvershootInterpolator(1.5f);
    transition.setInterpolator(interpolator);
    transition.setDuration(1500);
    android.support.transition.TransitionManager.beginDelayedTransition(animLay,transition);
    constraintSet.applyTo(animLay);
}

public void hide(){
    show =false;
    ConstraintSet constraintSet=new ConstraintSet();
    constraintSet.clone(this,R.layout.activity_login);
    android.support.transition.Transition transition=new android.support.transition.ChangeBounds();
    AnticipateOvershootInterpolator interpolator=new AnticipateOvershootInterpolator(1.5f);
    transition.setInterpolator(interpolator);
    transition.setDuration(1500);
    android.support.transition.TransitionManager.beginDelayedTransition(animLay,transition);
    constraintSet.applyTo(animLay);
}

0 个答案:

没有答案