LayoutTransition: 2 containers

南笙酒味 提交于 2020-01-06 02:47:08

问题


I'm trying out an official example on LayoutTransition.
I've modified it in order to have 2 containers. I add new items to 1'st (top) container with animation and the 2'nd (bottom) container moves down with slide animation, as expected.

But when I remove item from 1'st container, the whole 2'nd container goes beneath 1'st container, while 1'st container is shrinking height with animation (while animation is playing last element of 1'st and first element of 2'nd are intersecting).
Is there any way to make 2'nd container slide up while 1'st container is shrinking?

layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#ffffff">

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

        <LinearLayout android:id="@+id/container1"
            android:background="@drawable/border"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:showDividers="middle"
            android:divider="?android:dividerHorizontal"
            android:animateLayoutChanges="true"
            android:paddingLeft="16dp"
            android:paddingRight="16dp" />
    </ScrollView>

    <ScrollView
        android:layout_width="match_parent" android:layout_height="wrap_content">
        <LinearLayout android:id="@+id/container2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:showDividers="middle"
            android:divider="?android:dividerHorizontal"
            android:animateLayoutChanges="true"
            android:paddingLeft="16dp"
            android:paddingRight="16dp" />
    </ScrollView>
</RelativeLayout>

回答1:


This may not be the correct answer and it's definitely too late for this answer but it might be helpful and I had a similar issue where one item was disappearing and I wanted the second item to expand while the item was disappearing. I used setStartDelay() of LayoutTransition in code for both LayoutTransition.CHANGE_DISAPPEARING and LayoutTransition.DISAPPEARING to 0, as well as setDuration() of both to the same value. You might have to mess with those values for LayoutTransition.CHANGING, since that affects expanding views, but honestly LayoutTransition may not be capable of it (though I definitely don't know for sure), because while the expanding view is DEFINITELY CHANGING, the second item moving up is probably not CHANGE_DISAPPEARING, though you want a similar animation.

my code:

        customTransition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
        customTransition.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
        customTransition.setDuration(LayoutTransition.DISAPPEARING, hideArticleBar.getDuration());
        customTransition.setDuration(LayoutTransition.CHANGE_DISAPPEARING, hideArticleBar.getDuration());


来源:https://stackoverflow.com/questions/23703843/layouttransition-2-containers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!