我有一個回收視圖和cards.I要像向上輕掃手勢刪除card.My代碼:如何在RecyclerView,GridLayout中實現卡片刷卡?
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
data_list = new ArrayList<>();
load_data();
gridLayoutManager = new GridLayoutManager(this, 1,LinearLayoutManager.HORIZONTAL,false);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setHasFixedSize(true);
adapter = new CustomAdapter(this,data_list);
recyclerView.setAdapter(adapter);
CustomAdapterClass:
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
private Context context;
private List<MyData> my_data;
public CustomAdapter(Context context, List<MyData> my_data) {
this.context = context;
this.my_data = my_data;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card,parent,false);
itemView.setMinimumWidth(parent.getMeasuredWidth());
itemView.setMinimumHeight(parent.getMeasuredHeightAndState());
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position)
{
holder.userstory.setText(my_data.get(position).getUserstory());
holder.tasks.setText(my_data.get(position).getTask());
holder.actual.setText(my_data.get(position).getActuals());
holder.estimate.setText(my_data.get(position).getTodos());
}
@Override
public int getItemCount()
{
return my_data.size();
}
public class ViewHolder extends RecyclerView.ViewHolder
{
public TextView userstory,tasks,actual,estimate;
public CircularSeekBar seekbar;
public ViewHolder(View itemView)
{
super(itemView);
userstory=(TextView) itemView.findViewById(R.id.tvUserStory);
tasks=(TextView) itemView.findViewById(R.id.tvTask);
actual=(TextView) itemView.findViewById(R.id.tvActual);
estimate=(TextView) itemView.findViewById(R.id.tvEstimate);
}
}
}
我收到卡水平滾動視圖。我想添加滑動手勢來解僱它 我該如何實現這一目標?
也許這篇文章https://medium.com/@ipaulpro/drag-and-swipe-with-recyclervi ew-b9456d2b1aaf可以幫助你。 – beeb