Android开发banner效果
banner在每个app都会有的
一、思路:
用viewpager也可以做。但我是引进第三方库的
二、效果图:
三、关键代码:
// 联系:893151960
public class MainActivity extends AppCompatActivity {
private Banner mBanner;
private List<String> mBannerList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBannerList.add("https://i0.hdslb.com/bfs/article/ae851244f701be6b50c748d2ed7a862115336e38.jpg");
mBannerList.add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F201508%2F26%2F20150826162250_jHPQ8.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1697336048&t=2306f5ca261e219f9b872d1cd12d28ac");
mBannerList.add("https://i0.hdslb.com/bfs/archive/1309c38d26296819f0e70a1cb2dab45f96b6bebe.jpg");
mBanner = findViewById(R.id.banner);
mBanner.setAdapter(new BannerImageAdapter<String>(mBannerList) {
@Override
public void onBindView(BannerImageHolder holder, String data, int position, int size) {
ImgLoader.display(MainActivity.this,data,holder.imageView);
}
})
.setIndicator(new CircleIndicator(this))
.setIndicatorWidth(DpUtil.dp2px(MainActivity.this,6),DpUtil.dp2px(MainActivity.this,6))
.setIndicatorGravity(IndicatorConfig.Direction.CENTER);
mBanner.setOnBannerListener(new OnBannerListener() {
@Override
public void OnBannerClick(Object data, int position) {
}
});
}
}
四、项目demo源码结构图:
有问题或者需要完整源码demo的私信我