在android布局转换中排除某些元素的动画 [英] Exclude certain elements from being animated in android layout transitions

查看:24
本文介绍了在android布局转换中排除某些元素的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 android 布局转换框架的问题.特别是我想实现布局的某个部分根据另一个视图的可见性向下或向上滑动的效果.

I have a question regarding the android layout transition framework. In particular i want to achieve an effect that a certain part of an layout slides down or up depending on the visibility of another view(s).

想象以下布局.(请忽略此处嵌套的 LinearLayouts ;) )

Imagine the following layout. (And please overlook the nested LinearLayouts here ;) )

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

现在我想要实现的是,当 changedView1changedView2 改变它们的可见性时,movingView 会向上或向下滑动.

Now what i want to achieve is that when changingView1 and changingView2 change their visibility that movingView slides up or down.

通过为父布局启用 LayoutTransition.CHANGING,滑动部分可以正常工作.但这有一个副作用,即当添加或删除项目时 movingView 也会被动画化,因为这个布局改变了它的边界.这就是我的问题,因为这会导致看起来非常奇怪的动画.

By enabling the LayoutTransition.CHANGING for the parent layout the sliding part works fine so. But this has the side effect that the movingView will also be animated when there are being items added or removed because this layout changes its bounds. And here lies my problem because this results in a very strange looking animation.

回到我的问题.有没有办法保持滑动动画而不在 movingView 上设置布局边界变化的动画?

So back to my question. Is there a way to keep the sliding animation without animating layout bound changes on the movingView?

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

Disabling layoutTransitions on the movingView obviously does not help because this only effects the animations of the child views. I also tried playing around with enabling and disabling different LayoutTransitions on the parent layout but so far without the desired effect.

如果我可以添加更多详细信息,请告诉我,否则我希望有人可以帮助我.

If i can add more details please let me know otherwise i hope someone can help me out.

提前致谢!

推荐答案

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

I know it's late but hope it can help someone. Since android:animateLayoutChanges is the property of the direct parent, you can wrap your View/Layout in a FrameLayout (or some other ViewGroup) and set android:animateLayoutChanges="false" on the new parent.

这篇关于在android布局转换中排除某些元素的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆