san*_*nic 11 animation android android-layout android-cardview android-recyclerview
我正在寻找一个解决方案,这将允许我扩展cardview以查看更多信息,然后轻松崩溃它.Google Keep有这样的卡片示例.谁知道他们是怎么做到的?我会创建2个版本的cardview(一个折叠,一个展开),然后使用Animator类和手势方法在两个视图之间转换?我正在使用Recyclerview来保存我的卡片视图.
如果它完全相关,我发现了这个:http://developer.android.com/training/animation/layout.html
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:animateLayoutChanges="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
//here put the view which is always visible
<LinearLayout
android:layout_width="match_parent"
android:visibilty="gone"
android:id="@+id/expandableLayout"
android:layout_height="wrap_content">
//here put which will collapse and expand
</LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
在 arraylist 对象类中采用布尔值 isexpanded
if (listobj.isexpanded)
{
holder.expandableLayout.setVisibility(View.VISIBLE);
}
else {
holder.expandableLayout.setVisibility(View.GONE);
}
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listobj.isexpanded)
{
holder.expandableLayout.setVisibility(View.GONE);
listobj.isexpanded=false;
notifyItemChanged(position);
}
else {
holder.expandableLayout.setVisibility(View.VISIBLE);
listobj.isexpanded=true;
notifyItemChanged(position);
}
}
});
Run Code Online (Sandbox Code Playgroud)
尝试这样的事情