1. 集成依赖
dependencies {
compile 'com.wang.avi:library:2.1.3'
}
2.将控件添加到自己的布局
<com.wang.avi.AVLoadingIndicatorView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:indicatorName="BallPulseIndicator"
/>
控件样式:
/**
"BallPulseIndicator",
"BallGridPulseIndicator",
"BallClipRotateIndicator",
"BallClipRotatePulseIndicator",
"SquareSpinIndicator",
"BallClipRotateMultipleIndicator",
"BallPulseRiseIndicator",
"BallRotateIndicator",
"CubeTransitionIndicator",
"BallZigZagIndicator",
"BallZigZagDeflectIndicator",
"BallTrianglePathIndicator",
"BallScaleIndicator",
"LineScaleIndicator",
"LineScalePartyIndicator",
"BallScaleMultipleIndicator",
"BallPulseSyncIndicator",
"BallBeatIndicator",
"LineScalePulseOutIndicator",
"LineScalePulseOutRapidIndicator",
"BallScaleRippleIndicator",
"BallScaleRippleMultipleIndicator",
"BallSpinFadeLoaderIndicator",
"LineSpinFadeLoaderIndicator",
"TriangleSkewSpinIndicator",
"PacmanIndicator",
"BallGridBeatIndicator",
"SemiCircleSpinIndicator",
"com.wang.avi.sample.MyCustomIndicator"
*/
view.setIndicator("BallRotateIndicator");//可以设置多种样式
view.setIndicatorColor(Color.RED);//设置颜色
文章最后附上自己的一个LoadingUtil封装:
public class LoadingUtil {
private static Dialog dialog;
public static void Loading_show(Context context) {
if(dialog==null){
AVLoadingIndicatorView view = new AVLoadingIndicatorView(context);
view.setIndicator("BallRotateIndicator");
view.setIndicatorColor(Color.RED);
LinearLayout ll = new LinearLayout(context);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setGravity(Gravity.CENTER);
ll.addView(view,new LinearLayout.LayoutParams(200,200));
TextView tv = new TextView(context);
tv.setTextColor(Color.WHITE);
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
tv.setText("加载中,请稍后...");
ll.addView(tv,new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
dialog = new Dialog(context, R.style.lode_dialog);
dialog.setContentView(ll);// 设置布局
}
dialog.show();
}
public static void Loading_close() {
if(dialog!=null)dialog.cancel();
}
}