项目:89Tablayout
添加依赖
implementation 'com.youth.banner:banner:1.4.10'
implementation 'com.github.bumptech.glide:glide:4.5.0'
添加网络权限
<uses-permission android:name="android.permission.INTERNET"/>
Activity布局文件代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.youth.banner.Banner
android:id="@+id/Banner"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.youth.banner.Banner>
</RelativeLayout>
Activity文件代码
public class MainActivity extends AppCompatActivity {
private Banner banner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> Images=new ArrayList<>();
Images.add("http://photocdn.sohu.com/20130508/Img375182965.jpg");
Images.add("http://politics.people.com.cn/NMediaFile/2014/1201/MAIN201412012149000101473900009.jpg");
Images.add("http://photocdn.sohu.com/20110131/Img279172603.jpg");
banner=findViewById(R.id.Banner);
banner.setImageLoader(new Myimageloader());
banner.setImages(Images);
banner.start();
}
}
图片加载类
public class Myimageloader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
Glide.with(context).load(path).into(imageView);
}
}