compile 'com.wang.avi:library:2.1.3'
public class MyDialog { public static Dialog createLoadingDialog(Context context, String msg) { LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.dialog_loading, null);// 得到加载view FrameLayout layout = (FrameLayout) v.findViewById(R.id.dialog_view);// 加载布局 // main.xml中的ImageView AVLoadingIndicatorView avloading = (AVLoadingIndicatorView) v.findViewById(R.id.avloading); Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);// 创建自定义样式dialog loadingDialog.setCancelable(true);// 可以用“返回键”取消 loadingDialog.setContentView(layout);// 设置布局 return loadingDialog; } }
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:id="@+id/dialog_view" android:background="@color/bg_pink" android:layout_height="match_parent"> <com.wang.avi.AVLoadingIndicatorView android:id="@+id/avloading" android:layout_width="100dp" android:layout_gravity="center" android:layout_height="100dp" android:visibility="visible" app:indicator="Pacman" app:indicator_color="@color/white" /> </FrameLayout>
选择动画BallPulse
02.
BallGridPulse
03.
BallClipRotate
04.
BallClipRotatePulse
05.
SquareSpin
06.
BallClipRotateMultiple
07.
BallPulseRise
08.
BallRotate
09.
CubeTransition
10.
BallZigZag
11.
BallZigZagDeflect
12.
BallTrianglePath
13.
BallScale
14.
LineScale
15.
LineScaleParty
16.
BallScaleMultiple
17.
BallPulseSync
18.
BallBeat
19.
LineScalePulseOut
20.
LineScalePulseOutRapid
21.
BallScaleRipple
22.
BallScaleRippleMultiple
23.
BallSpinFadeLoader
24.
LineSpinFadeLoader
25.
TriangleSkewSpin
26.
Pacman
27.
BallGridBeat
28.
SemiCircleSpin
/** * 加载动画 */ public void loginAnimation(){ loadingDialog = MyDialog.createLoadingDialog(this, ""); WindowManager.LayoutParams lay = loadingDialog.getWindow().getAttributes(); setParams(lay); loadingDialog.show(); loadingDialog.dismiss(); } //获得屏幕大小 public void setParams(WindowManager.LayoutParams lay) { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); Rect rect = new Rect(); View view = getWindow().getDecorView(); view.getWindowVisibleDisplayFrame(rect); lay.height = dm.heightPixels - rect.top; lay.width = dm.widthPixels; } //关闭动画 public void dismissDialog(){ if (loadingDialog !=null){ loadingDialog.dismiss(); } }