我正在使用Swipecards此项目作为实现刷卡功能的参考。我对滑动功能感到满意,但我想要喜欢和不喜欢功能的两个不同按钮:我想做一些动画,例如向左和向右滑动。
这是我的适配器;我通过构造函数将我的按钮传递给Adapter。现在,您能否告诉我如何管理点击事件以使用动画删除卡?
public abstract class CardStackAdapter extends BaseAdapter {
private final Context mContext;
/**
* Lock used to modify the content of {@link #mData}. Any write operation
* performed on the deque should be synchronized on this lock.
*/
private final Object mLock = new Object();
private ArrayList<CardModel> mData;
public CardStackAdapter(Context context) {
mContext = context;
mData = new ArrayList<CardModel>();
}
public CardStackAdapter(Context context, Collection<? extends CardModel> items) {
mContext = context;
mData = new ArrayList<CardModel>(items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
FrameLayout wrapper = (FrameLayout) convertView;
FrameLayout innerWrapper;
View cardView;
View convertedCardView;
if (wrapper == null)
{
wrapper = new FrameLayout(mContext);
wrapper.setBackgroundResource(R.drawable.card_bg);
if (shouldFillCardBackground())
{
innerWrapper = new FrameLayout(mContext);
innerWrapper.setBackgroundColor(mContext.getResources().getColor(R.color.card_bg));
wrapper.addView(innerWrapper);
}
else
{
innerWrapper = wrapper;
}
cardView = getCardView(position, getCardModel(position), null, parent);
innerWrapper.addView(cardView);
}
else
{
if (shouldFillCardBackground())
{
innerWrapper = (FrameLayout) wrapper.getChildAt(0);
}
else
{
innerWrapper = wrapper;
}
cardView = innerWrapper.getChildAt(0);
convertedCardView = getCardView(position, getCardModel(position), cardView, parent);
if (convertedCardView != cardView)
{
wrapper.removeView(cardView);
wrapper.addView(convertedCardView);
}
}
return wrapper;
}
protected abstract View getCardView(int position, CardModel model, View convertView, ViewGroup parent);
public boolean shouldFillCardBackground()
{
return true;
}
public void add(CardModel item)
{
synchronized (mLock)
{
mData.add(item);
}
notifyDataSetChanged();
}
protected void removeItem(int position)
{
mData.remove(position);
notifyDataSetChanged();
}
public CardModel pop()
{
CardModel model;
synchronized (mLock)
{
model = mData.remove(mData.size() - 1);
}
notifyDataSetChanged();
return model;
}
@Override
public Object getItem(int position)
{
return getCardModel(position);
}
public CardModel getCardModel(int position)
{
synchronized (mLock)
{
return mData.get(mData.size() - 1 - position);
}
}
@Override
public int getCount()
{
return mData.size();
}
@Override
public long getItemId(int position)
{
return position;
}
public Context getContext()
{
return mContext;
}
}