banner无线轮播图(在fragment界面中写)

package wss.com.yuekaolianxi_02.frag;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;

import wss.com.yuekaolianxi_02.R;

public class Frag01 extends Fragment {

private Banner banner;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view =inflater.inflate(R.layout.frag001,container,false);

    //获取资源id
    banner = view.findViewById(R.id.frag001_banner);

    //创建图片地址集合
    ArrayList  imagelist=new ArrayList<>();
    //往集合添加
    imagelist.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic21363tj30ci08ct96.jpg");
    imagelist.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic259ohaj30ci08c74r.jpg");
    imagelist.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic2b16zuj30ci08cwf4.jpg");
    imagelist.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic2e7vsaj30ci08cglz.jpg");

    banner.setImageLoader(new ImageLoader() {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            com.nostra13.universalimageloader.core.ImageLoader instance = com.nostra13.universalimageloader.core.ImageLoader.getInstance();
            instance.displayImage((String) path,imageView);
        }
    });
    banner.setImages(imagelist);
    banner.start();
    return view;
}

}

你可能感兴趣的:(banner无线轮播图(在fragment界面中写))