我构建了一个简单的ImageViewPager,我把它放在了recyclerView的项目中,但似乎没有用,我错过了什么? 另一个问题是我的recyclerview拖拽是水平的,而viewPager的拖拽也是水平的。有没有办法在它们之间进行协调?
这是我的viewPager类 -
public class ImageViewPager extends ViewPager {
public ImageViewPager(@NonNull Context context) {
super(context);
}
public ImageViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public void setUrls(List<String> urls){
setAdapter(new ImagePagerAdapter(urls,getContext()));
}
private static class ImagePagerAdapter extends PagerAdapter{
private List<String> urls;
private Context context;
public ImagePagerAdapter(List<String> urls, Context context) {
this.urls = urls;
this.context = context;
}
@Override
public int getCount() {
return urls.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view.equals(object);
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
String photoUrl = urls.get(position);
View view = LayoutInflater.from(container.getContext()).inflate(R.layout.image_view_pager_lay,container,false);
ImageView imageView = view.findViewById(R.id.image_ImagePagerView);
Picasso.with(container.getContext()).load(photoUrl).fit().into(imageView);
container.addView(view,0);
return view;
}
}
}