图片滑动

懵懂的女人 提交于 2019-12-06 04:45:10
//图片public class PhotoViewPager extends ViewPager {    public PhotoViewPager(@NonNull Context context) {        this(context, null);    }    public PhotoViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {        super(context, attrs);    }    @Override    public boolean onTouchEvent(MotionEvent ev) {        try {            return super.onTouchEvent(ev);        } catch (IllegalArgumentException ex) {            ex.printStackTrace();        }        return false;    }    @Override    public boolean onInterceptTouchEvent(MotionEvent ev) {        try {            return super.onInterceptTouchEvent(ev);        } catch (IllegalArgumentException ex) {            ex.printStackTrace();        }        return false;    }}////////////////////////////////////////////////////
private ArrayList<View> viewList;/** * 初始化轮播 */public void initBanner(List<PhotoListResponse> responses) {    viewList = new ArrayList<View>();    for (int i = 0; responses != null && i < responses.size(); i++) {        LayoutInflater inflater = getLayoutInflater();        View view = inflater.inflate(R.layout.air_companyculture_activity_photo_view, null);        PhotoView photoView = view.findViewById(R.id.air_photo_view_photo);        String fileId = responses.get(i).getImagesInfo().get(0).getFileId();        GlideUtil.load(this, fileId, photoView);        viewList.add(view);    }    mAdapter = new PhotoPagerAdapter(viewList);    photoPager.setAdapter(mAdapter);    photoPager.setCurrentItem(s);    photoPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {        @Override        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {        }        @Override        public void onPageSelected(int position) {            dolike(position);        }        @Override        public void onPageScrollStateChanged(int state) {        }    });}///////////////////////////////////////////上面引用布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical">    <uk.co.senab.photoview.PhotoView        android:id="@+id/air_photo_view_photo"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:background="@color/c101" /></LinearLayout>//////////////////////////////////适配器
public class PhotoPagerAdapter extends PagerAdapter {    private ArrayList<View> viewList;    public PhotoPagerAdapter(ArrayList<View> viewList) {        this.viewList = viewList;    }    @Override    public boolean isViewFromObject(View arg0, Object arg1) {        return arg0 == arg1;    }    @Override    public int getCount() {        return viewList.size();    }    @Override    public void destroyItem(ViewGroup container, int position,                            Object object) {        container.removeView(viewList.get(position));    }    @Override    public Object instantiateItem(ViewGroup container, int position) {        container.addView(viewList.get(position));        return viewList.get(position);    }}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!