如何使用Glide库在Android中创建多图像图片轮播?
我已经使用Glide处理了单个图像,但无法用于创建图像轮播。有人可以帮我吗?
如何使用Glide库在Android中创建多图像图片轮播?
我已经使用Glide处理了单个图像,但无法用于创建图像轮播。有人可以帮我吗?
根据这个主题,我创建了自己的Custompageradapter:
public class CustomPagerAdapter extends PagerAdapter {
private static final String TAG = "ImageViewPage";
Context mContext;
LayoutInflater mLayoutInflater;
String[] mResources;
public CustomPagerAdapter(Context context, String[] resources) {
mContext = context;
mResources = resources;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mResources.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Log.d(TAG,
"instantiateItem() called with: " + "container = [" + container + "], position = [" + position + "]");
View itemView = mLayoutInflater.inflate(R.layout.item_pager, container, false);
Log.d(TAG, "load in gallery:" + mResources[position] + "#end");
final ImageView ivPhoto = (ImageView) itemView.findViewById(R.id.iv_photo);
if (!mResources[position].equals("")){
Glide.with(mContext)
.load(mResources[position].trim())
.crossFade()
.into(ivPhoto);
}
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
Log.d(TAG, "destroyItem() called with: " + "container = [" + container + "], position = [" + position
+ "], object = [" + object + "]");
container.removeView((LinearLayout) object);
}
}
我需要这样调用它:
String[] photoUrls = {"http://example/photo.jpg",
"http://example2.jpeg"};
ViewPager viewPager = (ViewPager) binding.slider;
if (viewPager != null) {
viewPager.setAdapter(new CustomPagerAdapter(getContext(), photoUrls));
}
你可以使用Android ViewFlipper。它很容易使用,就像你所说的,你已经能够将其用于一个图像,我希望你能够想出如何在多个图像上使用它,并且你的其他工作可以使用ViewFlipper完成。