Banner简单的使用

依赖包

compile 'com.youth.banner:banner:1.1.5'


Acticity中

private Banner banner;
private Button button;
private List<String> list;
private static final String BANNER[] = new String[]{
        "http://juheimg.oss-cn-ha…08_b329262313d97d9d.jpg",
        "http://juheimg.oss-cn-ha…08_2fb703a965d000b5.jpg",
        "http://juheimg.oss-cn-ha…08_6c53224efe151d84.jpg",
        "http://juheimg.oss-cn-ha…08_3ff0b4622ed21b57.jpg",
        "http://juheimg.oss-cn-ha…08_c7b4c6c2a9b6bd6d.jpg",
        "http://juheimg.oss-cn-ha…08_74128fa6ca93ca4a.jpg",
        "http://juheimg.oss-cn-ha…08_c9b044b98d2b1e8b.jpg",
        "http://juheimg.oss-cn-ha…08_06ea598f5f2593e2.jpg",
        "http://juheimg.oss-cn-ha…08_a528c52a13cf9f07.jpg",
        "http://juheimg.oss-cn-ha…08_b641527e8451f21a.jpg"
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    banner = (Banner) findViewById(R.id.banner);
    button = (Button) findViewById(R.id.button);

    list = new ArrayList<>();
    for(int i = 0;i<BANNER.length;i++){
        list.add(BANNER[i]);
    }

    //设置加载样式
    banner.setIndicatorGravity(Banner.CENTER);
    banner.setBannerStyle(Banner.CIRCLE_INDICATOR_TITLE);
    //是否自动轮播
    banner.isAutoPlay(true);
    //设置轮播的时间间隔
    banner.setDelayTime(2000);
    //设置加载的图片,解析出来的url
    banner.setImages(list);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MyActivity.this,MainActivity.class);
            startActivity(intent);
        }
    });


XML

<com.youth.banner.Banner
    android:id="@+id/banner"
    android:layout_width="match_parent"
    android:layout_height="300dp">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="跳过"
        android:layout_marginLeft="250dp"
        android:layout_marginTop="150dp"/>
</com.youth.banner.Banner>


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值