Android同时为两个视图设置可见性更改动画

Android同时为两个视图设置可见性更改动画,android,android-layout,android-animation,Android,Android Layout,Android Animation,单击按钮时,我想同时隐藏两个视图(一个查看页面和一个线性布局)。我试过使用android:animateLayoutChanges=“true”,但它总是先隐藏Viewpager,然后隐藏线性布局,这看起来不太好 如何同时手动隐藏两个视图?我见过这样的例子,其中一个视图的可见性发生了变化: myImageView.animate() .translationY(myImageView.getHeight()) .alpha(0.0f) .setDu

单击
按钮时,我想同时隐藏两个视图(一个
查看页面
和一个
线性布局
)。我试过使用android:animateLayoutChanges=“true”
,但它总是先隐藏
Viewpager
,然后隐藏
线性布局,这看起来不太好

如何同时手动隐藏两个视图?我见过这样的例子,其中一个视图的可见性发生了变化:

myImageView.animate()
        .translationY(myImageView.getHeight())
        .alpha(0.0f)
        .setDuration(300)
        .setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                myImageView.setVisibility(View.GONE);

            }
        });
是否有一种方法可以链接不同
视图的两个animate()调用以同时触发它们

编辑:这是我的布局文件,我想同时隐藏的
视图是带有id Viewpager的
Viewpager
,以及带有id ll_指示器的
线性布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <include
        android:id="@+id/tv_statusbar"
        layout="@layout/layout_statusbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/statusbar_height" />

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:textColor="@color/black"
        android:text="@string/some_text"
        android:padding="10dp"
        android:textSize="@dimen/fontSizeMedium"
        android:gravity="center_horizontal"
        android:layout_height="wrap_content" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <LinearLayout
        android:id="@+id/ll_indicators"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="horizontal">
        <ImageView
            android:id="@+id/intro_indicator_0"
            android:layout_width="8dp"
            android:layout_height="8dp"
            android:layout_marginEnd="@dimen/activity_margin_half"
            android:layout_marginRight="@dimen/activity_margin_half"
            android:background="@drawable/indicator_unselected" />

        <ImageView
            android:id="@+id/intro_indicator_1"
            android:layout_width="8dp"
            android:layout_height="8dp"
            android:layout_marginEnd="@dimen/activity_margin_half"
            android:layout_marginRight="@dimen/activity_margin_half"
            android:background="@drawable/indicator_unselected" />
    </LinearLayout>

    <include
        android:id="@+id/ll_login"
        android:layout_weight="0"
        layout="@layout/item_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </include>
</LinearLayout>

也许是这个


可能是这样的?

因为您没有发布布局,如果您可以将ViewPager和LinearLayout放在一个布局中(例如在RelativeLayout中),那么您可以将其设置为动画。

因为您没有发布布局,如果您可以将ViewPager和LinearLayout放在一个布局中(例如在RelativeLayout中)然后可以设置动画。

您可以只设置父线性布局的动画,其中的所有视图都将使用它设置动画:

yourLinearLayout.animate().setDuration(300).alpha(0).   ...
,或同时对两个视图调用animate():

  yourImageView.animate().alpha(0).    ...
  yourLinearLayout.animate().alpha(0).    ...

看起来它们同时消失了。

您可以只设置父线性布局的动画,其中的所有视图都将使用它设置动画:

yourLinearLayout.animate().setDuration(300).alpha(0).   ...
,或同时对两个视图调用animate():

  yourImageView.animate().alpha(0).    ...
  yourLinearLayout.animate().alpha(0).    ...

看起来它们同时消失了。

我已经更新了我的问题,ViewPager和LinearLayout是同一布局的一部分。好吧,然后将它们放在a中并设置动画。如果你想让我为你发布代码,请告诉我。我已经更新了我的问题,ViewPager和LinearLayout是同一布局的一部分。好吧,然后将它们放在a中并设置动画。如果你想让我帮你发密码,请告诉我。