alibaba / UltraViewPager

UltraViewPager is an extension for ViewPager to provide multiple features in a single ViewPager.
MIT License
5k stars 680 forks source link

setInfiniteLoop(true)后,setCurrentItem(pos)方法选中失效 #114

Open huyanghu opened 6 years ago

huyanghu commented 6 years ago

当设置setInfiniteLoop(false)后,setCurrentItem(pos)才有效

huyanghu commented 6 years ago

目前的解决方案: adapter = new HealthReportAdapter(data); mUltraViewPager.setAdapter(adapter); int pos = getArguments().getInt(KEY_POS);

        //内置indicator初始化
        mUltraViewPager.initIndicator();

//设置indicator样式 mUltraViewPager.getIndicator() .setOrientation(UltraViewPager.Orientation.HORIZONTAL) .setFocusColor(Utils.getColor(R.color.colorAccent)) .setNormalColor(Utils.getColor(R.color.color_59_57_57)) .setRadius((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics())) .setIndicatorPadding(Utils.dip2px(5)) .setMargin(0, 0, 0, Utils.dip2px(16));

//设置indicator对齐方式 mUltraViewPager.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); //构造indicator,绑定到UltraViewPager mUltraViewPager.getIndicator().build();

        mHandler.sendEmptyMessage(pos);

private Handler mHandler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        mUltraViewPager.setCurrentItem(msg.what);
    }
};

}