我正在使用castorflex VerticalViewPager,但它似乎与通常的ViewPager相同。
在更改滚动方向时显示错误的位置。
重点是:
我向下滚动几页并且具有位置0-> 1-> 2-> 3-> 4-> 5。然后我向上滚动,突然新页面的位置是2.
有人能解释我为什么会这样吗?
一些代码:
在我的情况下,有720页,我将其中一个设置为第一个显示的页面。从此页面第一次滚动后,位置编号立即出错。
final VerticalViewPager verticalViewPager = (VerticalViewPager) findViewById (R.id.verticalviewpager);
verticalViewPager.setAdapter(new myAdapter(getSupportFragmentManager()));
verticalViewPager.setOffscreenPageLimit(1);
verticalViewPager.setCurrentItem(initialPosition); //initialPosition=532
适配器:
public class myAdapter extends FragmentStatePagerAdapter {
public myAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
Log.d("Position", String.valueOf(position));
return PlaceholderFragment.newInstance(position);
}
@Override
public int getCount() {
return 720;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
return "PAGE" + String.valueOf(position);
}
}
片段:
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_layout, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.textview);
Log.d("CurPosition", String.valueOf(getArguments().getInt(ARG_SECTION_NUMBER)));
textView.setText(String.valueOf(getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
}