炫酷的loading框

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

本人一直想做个好看的loading框,技术不够,后来看到一个开源控件不错,就用这个控件然后加上自己的想法改成了一个dialog,觉得还不错,分享出来。没有废话,直接开干。

开源库地址:https://github.com/ybq/Android-SpinKit?utm_source=tuicool&utm_medium=referral

项目的build.gradle中:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

 工程项目中的build.gradle中:

    compile 'com.github.ybq:Android-SpinKit:1.1.0'

XML:


    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    app:SpinKit_Color="@color/colorAccent" />  

Java代码:

        //各种样式示例(更多样式见原开源库地址)
        ChasingDots chasingDots = new ChasingDots();
        DoubleBounce doubleBounce = new DoubleBounce();
        FoldingCube foldingCube = new FoldingCube();
        WanderingCubes wanderingCubes = new WanderingCubes();

        View inflate = LayoutInflater.from(getApplicationContext()).inflate(R.layout.test, null);
        SpinKitView viewById = (SpinKitView) inflate.findViewById(R.id.spin_kit);
        viewById.setIndeterminateDrawable(foldingCube);
        builder = new AlertDialog.Builder(MainActivity.this);
        //自定义dialog的布局样式
        builder.setCustomTitle(inflate);
        alertDialog = builder.create();
        alertDialog.setCancelable(true);
        //设置dialog框背景透明
        Window window = alertDialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.alpha = 0.7f;
        window.setAttributes(lp);
        
        alertDialog.setCanceledOnTouchOutside(true);

        alertDialog.show();

效果图(这里只贴了原来的样例图,dialog的效果图差不多,就不贴了):

炫酷的loading框_第1张图片

转载于:https://my.oschina.net/heyongrui/blog/864824

你可能感兴趣的:(炫酷的loading框)