Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中单击其他项目时如何在RecyclerView中扩展和折叠卡片视图_Android_Android Recyclerview_Collapse_Cardview - Fatal编程技术网

在android中单击其他项目时如何在RecyclerView中扩展和折叠卡片视图

在android中单击其他项目时如何在RecyclerView中扩展和折叠卡片视图,android,android-recyclerview,collapse,cardview,Android,Android Recyclerview,Collapse,Cardview,我想建立一个应用程序,使用回收视图和cardview,如下图所示,当用户点击该项目时,它将展开,当用户点击其他项目时,该项目将支出,支出的项目将崩溃。 例:我单击项目2,项目2将支出,然后我单击项目4,因此项目2将折叠,项目4将支出 非常感谢你的回答 您可以使用可展开的回收器视图(在github上提供)。如果您想使用回收器视图,您可以像切换一样通过动画展开和折叠视图。查看下面的代码: public static void expandCard(final View v) { v.me

我想建立一个应用程序,使用回收视图和cardview,如下图所示,当用户点击该项目时,它将展开,当用户点击其他项目时,该项目将支出,支出的项目将崩溃。 例:我单击项目2,项目2将支出,然后我单击项目4,因此项目2将折叠,项目4将支出


非常感谢你的回答

您可以使用可展开的回收器视图(在github上提供)。如果您想使用回收器视图,您可以像切换一样通过动画展开和折叠视图。查看下面的代码:

 public static void expandCard(final View v) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation()
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int)(targetHeight * interpolatedTime);
            v.requestLayout();
        }
        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    a.setDuration(((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density))*6);
    v.startAnimation(a);
}

public static void collapseCard(final View v) {
    final int initialHeight = v.getMeasuredHeight();
    Animation a = new Animation()
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if(interpolatedTime == 1){
                v.setVisibility(View.GONE);
            }else{
                v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }
        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    a.setDuration(((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density))*6);
    v.startAnimation(a);
}