问题:如果用户点击 Google入门应用之类的上一个按钮,如何重新获得所有以前的刷卡?
说明:
假设我有10张卡片。 001,002 ... 010。现在我开始刷卡。我刷了001、002和003,所以我目前看到的是004。现在我单击了上一个按钮。因此它显示003,这是正确的。
在那之后可能会发生两种用例:
1:假设我单击了上一个按钮,所以它应该显示002,但未显示。
2:假设我单击了下一个按钮,所以它应该再次显示004,这也显示并且是正确的,但是现在我再次单击了上一个按钮,但是这次却不显示003!
Google入门应用样本图片:enter image description here
我在项目中尝试了这些库类,因为我不想在项目中添加依赖项:https://github.com/flschweiger/SwipeStack
滑动堆栈适配器:
public class SwipeStackAdapter extends BaseAdapter {
public static final String TAG = SwipeStackAdapter.class.getSimpleName();
private List<String> mData;
public SwipeStackAdapter(List<String> data) {
this.mData = data;
}
@Override
public int getcount() {
return mData.size();
}
@Override
public String getItem(int position) {
return mData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position,View convertView,ViewGroup parent) {
convertView = LayoutInflater.from(parent.getcontext()).inflate(R.layout.card,parent,false);
TextView textViewCard = convertView.findViewById(R.id.textViewCard);
textViewCard.setText(mData.get(position));
return convertView;
}
private void showLog(String msg) {
Log.d(TAG,msg);
}
}
我在SwipeStack.java中找到了此方法:
private void addNextView() {
if (mCurrentViewIndex < mAdapter.getcount()) {
View bottomView = mAdapter.getView(mCurrentViewIndex,null,this);
bottomView.setTag(R.id.new_view,true);
if (!mDisableHwacceleration) {
bottomView.setLayerType(LAYER_TYPE_HARDWARE,null);
}
if (mViewRotation > 0) {
bottomView.setRotation(mRandom.nextInt(mViewRotation) - (mViewRotation / 2));
}
int width = getWidth() - (getPaddingLeft() + getPaddingRight());
int height = getHeight() - (getPaddingTop() + getPaddingBottom());
LayoutParams params = bottomView.getLayoutParams();
if (params == null) {
params = new LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,FrameLayout.LayoutParams.WRAP_CONTENT);
}
int measureSpecWidth = MeasureSpec.AT_MOST;
int measureSpecHeight = MeasureSpec.AT_MOST;
if (params.width == LayoutParams.MATCH_PARENT) {
measureSpecWidth = MeasureSpec.ExactLY;
}
if (params.height == LayoutParams.MATCH_PARENT) {
measureSpecHeight = MeasureSpec.ExactLY;
}
bottomView.measure(measureSpecWidth | width,measureSpecHeight | height);
addViewinlayout(bottomView,params,true);
mCurrentViewIndex++;
}
}
编辑:感谢Navneet Shamra的特殊帮助。非常感谢。非常感谢您的经验和才华。