輪播 網頁介面卡........
阿新 • • 發佈:2018-11-09
<主介面>
public class BannerAdapter extends PagerAdapter { private List<ImageView> imageViewList; public BannerAdapter(List<ImageView> imageViewList) { this.imageViewList = imageViewList; } @Override public int getCount() { return Integer.MAX_VALUE; } @Override public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { return view == object; } @NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, int position) { ImageView imageView = imageViewList.get(position % imageViewList.size()); ViewGroup parent = (ViewGroup) imageView.getParent(); if (parent != null){ parent.removeView(imageView); } container.addView(imageView); return imageView; } @Override public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { container.removeView((View) object); } }