设置滑动的距离

pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        for(int i=0;i<arr.size();i++)
        {
            if(position==i)
            {
                arr.get(i).setTextColor(Color.RED);
            }else
            {
                arr.get(i).setTextColor(Color.BLACK);
            }
        }
        TextView textView = arr.get(position);
        //20为margin值;
        int width = textView.getWidth()+20;
        hor.scrollTo((width + 20) * position, 0);

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
});

你可能感兴趣的:(设置滑动的距离)