我想做什么
我有一个默认情况下是隐藏的带有支持文本的CardView
。当用户单击“操作箭头”时,我想让卡片的这个部分可见,如下图所示:
我知道可以通过将该View
的可见性设置为VISIBLE
来实现,但我还想对扩展和折叠事件进行动画处理。
问题及我迄今为止尝试过的内容
为此,我在我的CardView
xml上使用了android:animateLayoutChanges="true"
属性,当它正在展开时它正常工作。但是一旦我再次点击箭头来折叠支持文本,动画期间下面的卡片会重叠在我点击的卡片上。如何避免这种重叠?
编辑: 我知道可能可以像这个问题的解决方案那样做一些事情,但看起来过于复杂,因为存在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);
}
}
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 -->
<!-- Omitted on purpose -->
<!-- ... -->
<!-- This is the support TextView -->
<TextView
android:id="@+id/tv_support"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/os_list_item_rl_actions"
android:text="@string/bacon_ipsum"
android:paddingBottom="24dp"
android:paddingEnd="16dp"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:visibility="gone"/>
</RelativeLayout>
</android.support.v7.widget.CardView>