码迷,mamicode.com
首页 > 其他好文 > 详细

图片滑动

时间:2019-11-30 15:21:00      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:pix   vertica   count   state   cti   vat   ges   attrs   err   

//图片
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);
}
}

图片滑动

标签:pix   vertica   count   state   cti   vat   ges   attrs   err   

原文地址:https://www.cnblogs.com/sunjian43792901/p/11962535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!