cardview android动画,android - 在RecyclerView中使用动画扩展/折叠CardView - 堆栈内存溢出...

凌成天
2023-12-01

我尝试使用此动画折叠单元

我需要在RecyclerView中将其用作Cardview,所有功能都非常出色,但是如果我尝试扩展/折叠一张卡,他会扩展/折叠更多卡。一个时间。 这是我的适配器的代码:

public class AllCorsiAdapter extends RecyclerView.Adapter{

private List corsiList;

private Context context;

// avatar

private String emptyAvatar = "@drawable/contruction";

private int imageRes;

public AllCorsiAdapter(List corsiList, Context context) {

this.corsiList = corsiList;

this.context = context;

}

@Override

public ScanViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(context).inflate(R.layout.single_card, null);

ScanViewHolder scanViewHolder = new ScanViewHolder(view);

return scanViewHolder;

}

@Override

public void onBindViewHolder(final ScanViewHolder holder, int position) {

MainActivity.Corso corso = corsiList.get(position);

holder.tvNomeCorsoT.setText(corso.getNome());

holder.tvNomeCorsoC.setText(corso.getNome());

holder.tvInfo.setText(corso.getDay()+", " + corso.getHr());

}

}

@Override

public int getItemCount() {

return corsiList.size();

}

public static class ScanViewHolder extends RecyclerView.ViewHolder {

TextView tvNomeCorsoT;

TextView tvNomeCorsoC;

TextView tvInfo;

ImageView ivCoverT;

ImageView ivCoverC;

CardView card;

FoldingCell fc;

public ScanViewHolder(final View itemView) {

super(itemView);

tvNomeCorsoT = (TextView) itemView.findViewById(R.id.tv_corsoname_title);

tvNomeCorsoC = (TextView) itemView.findViewById(R.id.tv_corsoname_content);

tvInfo = (TextView) itemView.findViewById(R.id.tv_infoCorso);

card = (CardView) itemView.findViewById(R.id.cvSingleCorso);

fc = (FoldingCell) itemView.findViewById(R.id.foldingCell);

fc.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

fc.toggle(false);

}

});

}

}

}

这是我的cardview .xml:

xmlns:card_view="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent" android:layout_height="match_parent">

android:id="@+id/cvSingleCorso"

android:layout_width="355dp"

android:layout_height="wrap_content"

card_view:cardBackgroundColor="#edf7f9"

card_view:cardCornerRadius="2dp"

card_view:cardElevation="7dp"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="5dp"

android:layout_marginBottom="5dp"

android:layout_marginLeft="3dp"

android:layout_marginRight="3dp">

xmlns:tools="http://schemas.android.com/tools"

xmlns:folding-cell="http://schemas.android.com/apk/res-auto"

android:id="@+id/foldingCell"

android:layout_width="match_parent"

android:layout_height="wrap_content"

folding-cell:animationDuration="1300"

folding-cell:cameraHeight="20"

android:clipChildren="false"

android:clipToPadding="false"

android:foreground="?selectableItemBackground"

android:clickable="true">

layout="@layout/cell_content_layout"

android:layout_alignParentStart="true"

android:layout_alignParentTop="true"

tools:ignore="IncludeLayoutParam" />

我认为问题出在这部分代码中:

fc = (FoldingCell) itemView.findViewById(R.id.foldingCell);

fc.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

fc.toggle(false);

}

});

在mainActivity.java中,我只是在循环中使用它来创建卡片:

...

// cardView

corsiList.add(new Corso(nome,giorno,orario,cover));

...

RecyclerView recyclerViewScan = (RecyclerView) findViewById(R.id.rvAllCorsi);

recyclerViewScan.setLayoutManager(new LinearLayoutManager(MainActivity.this));

AllCorsiAdapter allCorsiAdapter = new AllCorsiAdapter(corsiList,MainActivity.this);

recyclerViewScan.setAdapter(allCorsiAdapter);

....

我已经尝试了所有方法,也尝试了在线操作,但是似乎没有人遇到我的问题。

 类似资料: