以下是我的instantiateItem方法
@Override
public Object instantiateItem(ViewGroup container, int position) {
View itemView = mLayoutInflater.inflate(R.layout.pager_item, container, false);
ImageView imageView = (ImageView) itemView.findViewById(R.id.img);
TextView textView = (TextView) itemView.findViewById(R.id.txt);
imageView.setImageResource(mResources[position]);
textView.setText(mCompanies[position]);
container.addView(itemView);
return itemView;
}
我想通过滚动来检测用户是否已到达视图寻呼机的末尾,如果用户已到达结尾,我想从左到右摇动整个viewpager。我怎么能这样做?
答案 0 :(得分:2)
@Override
public void onPageScrollStateChanged(int state) {
//mImageResource is image array
if(state<mImageResources.length)
{
//intro_images is viewpager
intro_images.setCurrentItem(0,true);
}
}
答案 1 :(得分:1)
你可以使用OnPageChangeListener来实现这个
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
if(position == lastPosition){
pager.setCurrentItem(0, true);
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});