我在这里有这个自定义的“底部操作栏”:https ://youtu.be/TPi5jtcs2wE ,它随着某些类型的网页(例如文章/非文章)出现和消失。我设置了最外层LinearLayout
并animateLayoutTransition
制作了一个不同的LayoutTransition
对象,但我希望栏在 webview 调整其高度的同时消失。需要明确的是,栏(relativeLayout)被设置为View.GONE
并且 webView 应该扩展以匹配父级(由于 layout_weight),因为栏已经消失,但它不会同时进行。我尝试更改LayoutTransition.setDuration()
和.setStartDelay()
.
文章Activity xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/container_article"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.morningsignout.com.morningsignoff.ArticleActivity"
tools:ignore="MergeRootFrame"
android:background="@android:color/white"
android:animateLayoutChanges="true">
<app.com.morningsignout.morningsignout.CustomWebView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/webView_article"
android:layout_gravity="center"
android:layout_weight="9" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:layout_weight="0"
LayoutTransition的配置:
LinearLayout container = (LinearLayout) findViewById(R.id.container_article);
LayoutTransition customTransition = new LayoutTransition();
customTransition.enableTransitionType(LayoutTransition.CHANGING);
customTransition.disableTransitionType(LayoutTransition.CHANGE_APPEARING);
customTransition.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING);
customTransition.setAnimator(LayoutTransition.APPEARING, showArticleBar);
customTransition.setAnimator(LayoutTransition.DISAPPEARING, hideArticleBar);
customTransition.setStartDelay(LayoutTransition.APPEARING, 0);
customTransition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
customTransition.setStartDelay(LayoutTransition.CHANGING, 0);
customTransition.setDuration(LayoutTransition.APPEARING, showArticleBar.getDuration());
customTransition.setDuration(LayoutTransition.DISAPPEARING, hideArticleBar.getDuration());
customTransition.setDuration(LayoutTransition.APPEARING, showArticleBar.getDuration());
container.setLayoutTransition(customTransition);
hide_action_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="translationY"
android:duration="300"
android:valueFrom="0"
android:valueTo="?android:attr/actionBarSize"/>
show_action_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="translationY"
android:duration="300"
android:valueFrom="?android:attr/actionBarSize"
android:valueTo="0"/>
我虽然LayoutTransition.CHANGING
动画会让它工作,但没有。如何让 webView 的高度变化和条形图的移除同时发生?尽管设置了持续时间和开始延迟排队,但它不起作用。我认为问题是CHANGING
必须在之后发生,View.GONE
因为在视图消失后需要知道高度。不管是那个还是这个都不是CHANGING
动画。