如何在android中刷另一行后自动关闭滑动?

时间:2017-04-25 11:49:49

标签: android

我想要实现的是我在Recycler视图中使用view pager进行滑动。现在我能够获得刷卡行的当前位置。现在我想要实现的是,例如我已经将第1行向左滑动然后如果我向左滑动第2行,则第1行应该自动向右滑动。 我怎样才能做到这一点。

这是我的viewPager onTouch监听器:

holder.viewPager.setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        presentPosition = holder.getAdapterPosition();

        if(globalPosition == presentPosition) {

            //do nothing

            System.out.println("present position equal is  " + globalPosition);

        } else {

            //close the previous swipe

            ManageCustomerModelObject modelObject = ManageCustomerModelObject.values()[0];
            modelObject.setmLayoutResId(0);

            System.out.println("present position not equal is  " + globalPosition);

            globalPosition = presentPosition;
        }
        return false;
    }
});

这是我的观点寻呼机适配器代码段:

 public Object instantiateItem(ViewGroup collection, int position) {
        System.out.println("viewpager position " + patientPosition);

        ManageCustomerModelObject modelObject = ManageCustomerModelObject.values()[position];
        LayoutInflater inflater = LayoutInflater.from(mContext);
        ViewGroup layout = (ViewGroup) inflater.inflate(modelObject.getLayoutResId(), collection, false);
        collection.addView(layout);
}

这是我的modelObejct代码:

public enum ManageCustomerModelObject {

    BEFORE_SWIPE(R.string.before_swipe, R.layout.before_swipe),
    AFTER_SWIPE(R.string.after_swipe, R.layout.after_swipe);

    public int mTitleResId;
    public int mLayoutResId;

     ManageCustomerModelObject(int titleResId, int layoutResId) {
        mTitleResId = titleResId;
        mLayoutResId = layoutResId;
    }

    public void setmLayoutResId(int mLayoutResId) {
        this.mLayoutResId = mLayoutResId;
    }

    public int getTitleResId() {
        return mTitleResId;
    }

    public int getLayoutResId() {
        return mLayoutResId;
    }

}

0 个答案:

没有答案