public class Fragment_main1 extends Fragment { private Banner banner; private List<BannerBean.RowsDTO> list; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_main1, container, false); } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); initView(view); initDatas(); } private void initDatas() { initBanner(); } private void initBanner(){ list = new ArrayList<>(); list.add(new BannerBean.RowsDTO(AppConifg.IP+"/prod-api/profile/upload/image/2021/05/06/b9d9f081-8a76-41dc-8199-23bcb3a64fcc.png")); list.add(new BannerBean.RowsDTO(AppConifg.IP+"/prod-api/profile/upload/image/2021/05/06/e614cb7f-63b0-4cda-bf47-db286ea1b074.png")); list.add(new BannerBean.RowsDTO(AppConifg.IP+"/prod-api/profile/upload/image/2021/05/06/242e06f7-9fb0-4e16-b197-206f999c98f2.png")); //Log.i("liuhua",list.get(1).getAdvImg()); banner.setAdapter(new BannerImageAdapter<BannerBean.RowsDTO>(list) { @Override public void onBindView(BannerImageHolder holder, BannerBean.RowsDTO data, int position, int size) { Glide.with(getActivity()) .load(data.getAdvImg()) .into(holder.imageView); } }).addBannerLifecycleObserver(this) .setIndicator(new CircleIndicator(getActivity())); } private void initView(View a){ banner = a.findViewById(R.id.banner); } }
时间: 2024-04-27 21:19:27 浏览: 100
Android Fragment滑动组件ViewPager的实例详解
这段代码是一个 Android Fragment 的实现,主要功能是初始化一个图片轮播控件 Banner。其中 initBanner() 方法中会将图片地址列表 list 绑定到 Banner 控件上,并使用 Glide 加载图片。如果您遇到了问题,请具体描述一下问题的现象和出现的环境,我会尽力帮助您解决。
阅读全文