gpt4 book ai didi

android - LayoutTransition 消失和改变不会同时发生

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:17:06 24 4
gpt4 key购买 nike

我这里有这个自定义的“底部操作栏”:https://youtu.be/TPi5jtcs2wE ,随着某些类型的网页(例如文章/非文章)出现和消失。我用 animateLayoutTransition 设置了最外层的 LinearLayout 并制作了一个不同的 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);

隐藏操作栏.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 之后发生,因为在 View 消失后需要知道高度。那个或这个不是 CHANGING 动画。

最佳答案

我想通了。结果我需要 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 位置,这是错误的(应该在新页面的页面顶部)。我通过将 webview 包含在 linearLayout 中来修复它。

<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"...

关于android - LayoutTransition 消失和改变不会同时发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32692341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com