图片滑动

Posted sunjian43792901

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图片滑动相关的知识,希望对你有一定的参考价值。

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

以上是关于图片滑动的主要内容,如果未能解决你的问题,请参考以下文章

vue图片溢出滑动

在viewpager中图片滑动展示时图片与文字对应不上?

JS实例之图片滑动效果,实例图片滑动进场

展示图片和平移滑动

viewpage 循环滑动播放图片

如何只用AngularJs实现图片滑动切换?