排除某些元素在android布局转换中不显示动画效果

问题描述 投票:8回答:2

我对android布局转换框架有疑问。特别是我想实现一种效果,即布局的某个部分根据另一个视图的可见性上下滑动。

想象以下布局。 (并且请在这里忽略嵌套的LinearLayouts)))>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <View
                android:id="@+id/changingView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"/>

        <View
                android:id="@+id/changingView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"/>

    </LinearLayout>

    <LinearLayout
            android:id="@+id/movingView"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:animateLayoutChanges="false"/>

</LinearLayout>

现在我要实现的是,当changingView1

changingView2更改movingView上下滑动的可见性时。

通过为父布局启用LayoutTransition.CHANGING

,滑动部分可以正常工作。但这有一个副作用,当添加或删除项目时,movingView也会被动画化,因为此布局会更改其边界。我的问题就在这里,因为这会导致看起来很奇怪的动画。

回到我的问题。有没有一种方法可以保持滑动动画而不在movingView

上设置布局绑定动画的动画?]

movingView

上禁用layoutTransitions显然没有帮助,因为这只会影响子视图的动画。我还尝试过在父布局上启用和禁用不同的LayoutTransitions,但是到目前为止还没有达到预期的效果。

如果我可以添加更多详细信息,请让我知道,否则我希望有人可以帮助我。

提前感谢!

我对android布局转换框架有疑问。我特别想实现一种效果,即布局的某个部分根据另一个可视性向下或向上滑动...

android android-animation layouttransition
2个回答
2
投票

我知道已经晚了,但希望它能对某人有所帮助。由于android:animateLayoutChanges是直接父级的属性,因此您可以将View / Layout包装在FrameLayout(或其他一些ViewGroup)中,并在新父级上设置android:animateLayoutChanges="false"


0
投票

为了避免不必要的动画,您可以在需要时通过代码删除动画布局更改,如下所示:

© www.soinside.com 2019 - 2024. All rights reserved.