我正在使用 viewpager 从左到右和从右到左滑动图像,它工作得很好。但是,当向右滑动显示最后一张图像时,什么也没有发生。我希望在显示最后一张图像时向右滑动第一张图像..同样我希望在显示第一张图像时向左滑动最后一张图像...
将等待一些线索..
我正在使用以下代码:
public class PhotoFullActivity extends Activity{
private FlingViewPager viewPager;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
viewPager = new FlingViewPager(this);
setContentView(viewPager);
FlingAdapter adapter = new FlingAdapter(this, photoArrayList); //photoArrayList is the collection of phot path from SD card
viewPager.setAdapter(adapter);
}
==================================================== ================
public class FlingViewPager extends ViewPager {
public FlingViewPager(Context context) {
super(context);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException e) {
e.printStackTrace();
return false;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
==================================================== =========
public class FlingAdapter extends PagerAdapter{
private Context context;
ArrayList<String> adapterList;
public FlingAdapter(Context context,ArrayList<String> adapterList)
{
this.context = context;
this.adapterList = adapterList;
}
public View instantiateItem(ViewGroup container, int position) {
PhotoView photoView = new PhotoView(container.getContext());
String photo_path = adapterList.get(position);
File file = new File(photo_path);
Bitmap bmp_thumb = BitmapFactory.decodeFile(file.getAbsolutePath());
photoView.setImageBitmap(bmp_thumb);
// Now just add PhotoView to ViewPager and return it
container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
return photoView;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return this.adapterList.size();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
感谢和问候