【发布时间】:2016-09-07 11:43:21
【问题描述】:
我想在单击 Button 时同时隐藏两个视图(Viewpager 和 LinearLayout)。我尝试使用android:animateLayoutChanges="true",但它总是会先隐藏Viewpager,然后再隐藏LinearLayout,看起来不太好。
如何同时手动隐藏两个视图?我见过这样的例子,其中一个视图的可见性发生了变化:
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);
}
});
有没有办法链接两个不同 Views 的 animate() 调用以同时触发它们?
编辑:这是我的布局文件,我要同时隐藏的Views 是带有id viewpager 的Viewpager 和带有id ll_indicators 的LinearLayout:
<?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>
【问题讨论】:
标签: android android-layout android-animation