我如何知道用户在 View 寻呼机中是向右还是向左滑动屏幕?

indicator.setOnPageChangeListener(new OnPageChangeListener() {

    @Override
    public void onPageSelected (int page)
    {
        //page changed
    }

    @Override
    public void onPageScrolled (int arg0, float arg1, int arg2)
    {
    }

    @Override
    public void onPageScrollStateChanged (int arg0)
    {
    }
});

我使用了这种方法,我很确定 onpagescrollstatechanged 是告诉我们它是向右还是向左的方法,但我们如何使用它?

最佳答案

将值单独保存在另一个变量中并在pagescrollstate 上进行比较。

OnPageChangeListener onPageChangeListener = new OnPageChangeListener() {

                @Override
                public void onPageSelected(int arg0) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onPageScrolled(int arg0, float arg1, int arg2) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onPageScrollStateChanged(int arg0) {
                    // TODO Auto-generated method stub
                    if(savePosition>arg0)
                    {
                        Toast.makeText(getApplicationContext(), "Swiped Right", Toast.LENGTH_SHORT).show();
                    }else
                    {
                        Toast.makeText(getApplicationContext(), "Swiped Left", Toast.LENGTH_SHORT).show();
                    }
                    savePosition = arg0;
                }
            };

关于android - viewpager 屏幕向右或向左滑动?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24800215/

10-12 04:21