使用动画“扩展更多”

时间:2016-09-12 07:50:43

标签: android xml android-linearlayout expandable

我正在尝试使用与Google相同的动画: https://vid.me/9Wli

关于我的应用的快速解释:

在顶部我有一个AppBar,在它下面有一个LinearLayout,包括一个用于扩展更多信息的按钮,在这个LinearLayout下方,我有一个RecyclerView。

目前,当我点击“展开更多”按钮时,我只会显示一些带有.setVisibility(View.VISIBLE)的项目,所以我没有动画。

这是我的实际XML代码:

<LinearLayout
    android:id="@+id/expandable_zone"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:visibility="gone">

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

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_width="wrap_content"
            android:text="@string/expandable_1"
            android:textColor="@color/secondaryTextDark"
            android:textSize="13dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_expandable_zone"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical">

        <TextView
            android:animateLayoutChanges="true"
            android:id="@+id/expand_more"
            android:layout_gravity="center_horizontal"
            android:layout_height="wrap_content"
            android:layout_marginBottom="11sp"
            android:layout_marginTop="11sp"
            android:layout_width="wrap_content"
            android:text="@string/expand_more"
            android:textColor="@color/secondaryTextDark" />

        <ImageButton
            android:background="@drawable/circle_shape"
            android:id="@+id/expand_less"
            android:layout_gravity="center_horizontal"
            android:layout_height="wrap_content"
            android:layout_marginBottom="11sp"
            android:layout_marginTop="10sp"
            android:layout_width="wrap_content"
            android:src="@drawable/ic_check_grey600_24dp"
            android:visibility="gone" />
    </LinearLayout>
</LinearLayout>

有人能给我最好的解决方案吗?

1 个答案:

答案 0 :(得分:1)

android:animateLayoutChanges="true"
在LinearLayout上设置它 android:id="@+id/bottom_expandable_zone"

如果这不会帮助你需要搜索stackoverflow如何动画视图并在android:id="@+id/bottom_expandable_zone"上实现它