相关疑难解决方法(0)

在动画制作时,在RecyclerView内部折叠CardView

我想做什么

CardView在底部有一个支持文本GONE,默认情况下.我想只在用户点击"操作箭头"时才能看到卡片的这一部分,如下图所示:

展开箭头

我知道我可以通过简单地设置View可见性来实现这一目标VISIBLE,但我也希望为扩展和崩溃事件设置动画.

问题和我到目前为止所尝试的内容

要做到这一点,我已经android:animateLayoutChanges="true"在我的CardViewxml 上使用了该属性,并且它在扩展时工作得很好.但是,一旦我再次点击箭头折叠支持文本,下面的卡片就会重叠我在动画期间点击过的卡片.我怎样才能避免这种重叠?

编辑:我知道有可能做一些像这个问题解决方案,但它似乎过于复杂,因为该android:animateLayoutChanges选项存在.我想知道是否可以使用该XML属性解决我的问题,以保持简单.

我的动画代码如下:

Java代码

protected void expandCard() {
    if (isExpanded) {
        ibt_show_more.animate().rotation(0).start();
        isExpanded = false;
        tv_support.setVisibility(View.GONE);
    }
    else {
        ibt_show_more.animate().rotation(180).start();
        isExpanded = true;
        tv_support.setVisibility(View.VISIBLE);
    }
}
Run Code Online (Sandbox Code Playgroud)

XML代码

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/spacing_small"
    card_view:cardCornerRadius="2dp"
    android:id="@+id/os_list_item_cv">

    <RelativeLayout
        android:id="@+id/os_list_item_rl_root"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true">

        <!-- Here goes the header, the image, the action buttons and so on -->
        <!-- …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-cardview

18
推荐指数
1
解决办法
3151
查看次数