FlyBanner無線輪播
阿新 • • 發佈:2018-11-30
切記!匯入依賴
implementation ‘com.recker.flybanner:flybanner:1.3’
本地輪播網路輪播根據自己的需求來
public class Stwo extends Fragment { private FlyBanner flyBanner; //有地址是為了得到地址裡面的圖片地址(使用HiJson檢視) private String path = "http://api.expoon.com/AppNews/getNewsList/type/1/p/1"; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.stwo,container,false); //獲取資源ID flyBanner = v.findViewById(R.id.banner); return v; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //網路的 List<String> list=new ArrayList<>(); list.add("http://f.expoon.com/sub/news/2016/01/21/887844_230x162_0.jpg"); list.add("http://f.expoon.com/sub/news/2016/01/21/580828_230x162_0.jpg"); list.add("http://f.expoon.com/sub/news/2016/01/21/745921_230x162_0.jpg"); flyBanner.setImagesUrl(list); //本地圖片 List<Integer> lists = new ArrayList<>(); lists.add(R.mipmap.a); lists.add(R.mipmap.b); lists.add(R.mipmap.c); flyBanner.setImages(lists); } }
2.Xml的佈局
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.recker.flybanner.FlyBanner android:id="@+id/banner" android:layout_width="match_parent" android:layout_height="200dp"></com.recker.flybanner.FlyBanner> </android.support.constraint.ConstraintLayout>