欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Xbunder

程序员文章站 2022-07-06 19:59:37
...

xbanner使用步骤

    implementation 'com.xhb:xbanner:1.3.1'
public interface IMainView extends IBaseView {
    void onSuccess(ShopBean shopBean);

    void onFail(String msg);

    void onBunder(BunderBean bunder);
}
public class MainPresenter extends BasePresenter<IMainView> {
    private final String Url = "http://172.17.8.100/small/commodity/v1/commodityList";
    private final String Bund ="http://172.17.8.100/small/commodity/v1/bannerShow";
    private final HttpUtils httpUtils;

    public MainPresenter() {
        httpUtils = HttpUtils.getInstance();
    }

    public void loadNetData() {
        httpUtils.getData(Url, ShopBean.class, new HttpUtils.CallBackdata<ShopBean>() {
            @Override
            public void onFail(String mg) {
                getView().onFail(mg);
            }

            @Override
            public void onResponse(ShopBean t) {
                Message message = handler.obtainMessage();
                message.what = 0;
                message.obj = t;
                handler.sendMessage(message);
            }


        });
    }
    public void bunderdata() {
        httpUtils.getData(Bund, BunderBean.class, new HttpUtils.CallBackdata<BunderBean>() {
            @Override
            public void onFail(String mg) {
                getView().onFail(mg);
            }

            @Override
            public void onResponse(BunderBean t) {
                Message message = handler.obtainMessage();
                message.what = 1;
                message.obj = t;
                handler.sendMessage(message);
            }


        });
    }
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    ShopBean shopBean= (ShopBean) msg.obj;
                    getView().onSuccess(shopBean);
                    break;
                case 1:
                    BunderBean bannerBean= (BunderBean) msg.obj;
                    getView().onBunder(bannerBean);
                    break;
            }

        }
    };
}

 @Override
    public void onBunder(BunderBean bunder) {

        final List<BunderBean.ResultBean> result = bunder.getResult();
        final ArrayList<String> objects = new ArrayList<>();
        for (int i = 0; i < result.size(); i++) {
            objects.add(result.get(i).getImageUrl());
        }
        xBanner.setData(objects, null);
        xBanner.setmAdapter(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                Glide.with(MainActivity.this).load(objects.get(position)).into((ImageView) view);
            }
        });
        xBanner.setPageTransformer(Transformer.Default);//横向移动

        xBanner.setPageTransformer(Transformer.Alpha); //渐变,效果不明显

        xBanner.setPageTransformer(Transformer.Rotate);  //单页旋转

        xBanner.setPageTransformer(Transformer.Cube);    //立体旋转

        xBanner.setPageTransformer(Transformer.Flip);  // 反转效果

        xBanner.setPageTransformer(Transformer.Accordion); //三角换页

        xBanner.setPageTransformer(Transformer.ZoomFade); // 缩小本页,同时放大另一页

        xBanner.setPageTransformer(Transformer.ZoomCenter); //本页缩小一点,另一页就放大

        xBanner.setPageTransformer(Transformer.ZoomStack); // 本页和下页同事缩小和放大

        xBanner.setPageTransformer(Transformer.Stack);  //本页和下页同时左移

        xBanner.setPageTransformer(Transformer.Depth);  //本页左移,下页从后面出来

        xBanner.setPageTransformer(Transformer.Zoom);  //本页刚左移,下页就在后面
        // 设置XBanner页面切换的时间,即动画时长
        xBanner.setPageChangeDuration(1000);
    }
相关标签: 4

推荐阅读