轮播图(3d画廊效果)

首先需要将轮播图的依赖导入

implementation 'com.github.xiaohaibin:XBanner:1.6.1'

接下来就是在项目目录下bulidgradle中导入(allprojects)

//Xbanner第一步
maven { url 'https://jitpack.io' }
ext {
    // Sdk and tools
    minSdkVersion = 17 //和model 下的build.gradle版本对应
    targetSdkVersion = 28
    compileSdkVersion = 28
    buildToolsVersion = '28.0.2'
    //support版本
    supportVersion = '28.1.0'
    constraintLayout = '1.0.2'
    junit = '4.12'
    testRunner = '1.0.1'
    espressoCore = '3.0.1'

    interceptor = "3.11.0"
    retrofit = '2.3.0'
    converterGson = '2.3.0'
    rxandroid = '1.2.1'
    rxjava = '1.3.0'
    rxbus = '1.0.6'
    adapterRxjava = '2.0.2'
}

//在轮播图回调方法中调用

@Override
public void BannerSuccess(final List list) {
    if (list != null) {
        ArrayList mlist = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            mlist.add(list.get(i).getImageUrl());
        }
        homefragment_xbanner.setData(list, null);
        mXBannerAdapter = new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                //设置图片圆角角度
                RoundedCorners roundedCorners = new RoundedCorners(10);
                //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
                RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 150);
                Glide.with(getActivity()).load(list.get(position).getImageUrl()).apply(options).into((ImageView) view);
            }
        };
        homefragment_xbanner.loadImage(mXBannerAdapter);
        homefragment_xbanner.setPageTransformer(Transformer.Default);//横向移动
        homefragment_xbanner.setPageTransformer(Transformer.Alpha); //渐变,效果不明显
        homefragment_xbanner.setPageTransformer(Transformer.ZoomFade); // 缩小本页,同时放大另一页
        homefragment_xbanner.setPageTransformer(Transformer.ZoomCenter); //本页缩小一点,另一页就放大
        homefragment_xbanner.setPageTransformer(Transformer.ZoomStack); // 本页和下页同事缩小和放大
        homefragment_xbanner.setPageTransformer(Transformer.Stack);  //本页和下页同时左移
        homefragment_xbanner.setPageTransformer(Transformer.Depth);  //本页左移,下页从后面出来
        homefragment_xbanner.setPageTransformer(Transformer.Zoom);  //本页刚左移,下页就在后面
        // 设置XBanner页面切换的时间,即动画时长
        homefragment_xbanner.setPageChangeDuration(1);

    }
}

//xml文件


    

 

你可能感兴趣的:(轮播图(3d画廊效果))