我在这里有这个自定义“底部操作栏”:https://youtu.be/TPi5jtcs2wE,它出现并随着某些类型的网页而消失(例如文章/非文章)。我使用LinearLayout
设置了最外面的animateLayoutTransition
并创建了一个不同的LayoutTransition
对象,但我希望该栏在webview调整其高度的同时消失。为了清楚起见,bar(relativeLayout)被设置为View.GONE
,并且webView应该展开以匹配parent(由于layout_weight),因为条形图已经消失,但它不会同时执行这两个操作。我尝试更改LayoutTransition.setDuration()
和.setStartDelay()
。
articleActivity 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
动画。
答案 0 :(得分:2)
我明白了。结果我需要CHANGE_APPEARING和CHANGE_DISAPPEARING以使其更平滑,而不是改变。它并不完美,但现在两个动画同时发生。我尝试了实际的顶级操作栏的hide()/ show()函数,我认为这是正常的。
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.CHANGE_APPEARING, 0);
customTransition.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
// customTransition.setStartDelay(LayoutTransition.CHANGING, 0);
customTransition.setDuration(LayoutTransition.APPEARING, showArticleBar.getDuration());
customTransition.setDuration(LayoutTransition.DISAPPEARING, hideArticleBar.getDuration());
customTransition.setDuration(LayoutTransition.CHANGE_APPEARING, showArticleBar.getDuration());
customTransition.setDuration(LayoutTransition.CHANGE_DISAPPEARING, hideArticleBar.getDuration());
// customTransition.setDuration(LayoutTransition.APPEARING, showArticleBar.getDuration());
container.setLayoutTransition(customTransition);
这会产生一个问题,即webview在新网页上保留了scrollY位置,这是错误的(应该在新页面的页面顶部)。我通过在linearLayout中包含webview来修复它。
<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/transparent"
android:animateLayoutChanges="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9">
<app.com.morningsignout.morningsignout.CustomWebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView_article"
android:layout_gravity="center" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:layout_weight="0"...