Android开发:Android加载中动画AVLoadingI
2018-04-18 本文已影响1181人
Jason_hzb
第三方效果图:
11.gif
第三方GitHub地址
https://github.com/hanzhanbing/AVLoadingIndicatorView
实际使用:
Step 1:
bulid.gradle
dependencies {
compile 'com.wang.avi:library:2.1.3'
}
Step 2:
dialog_loading.xml
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/avi"
style="@style/AVLoadingIndicatorView.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:indicatorColor="#FF0000"
app:indicatorName="LineSpinFadeLoaderIndicator" />
</RelativeLayout>
Step 3:
style.xml
<style name="TransparentDialog" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
Step 4:
LoadingDialog.java
/**
* 加载中Dialog
*
* @author hzb
*/
public class LoadingDialog extends AlertDialog {
private static LoadingDialog loadingDialog;
private AVLoadingIndicatorView avi;
public static LoadingDialog getInstance(Context context) {
loadingDialog = new LoadingDialog(context, R.style.TransparentDialog); //设置AlertDialog背景透明
loadingDialog.setCancelable(false);
loadingDialog.setCanceledOnTouchOutside(false);
return loadingDialog;
}
public LoadingDialog(Context context, int themeResId) {
super(context,themeResId);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.dialog_loading);
avi = (AVLoadingIndicatorView)this.findViewById(R.id.avi);
}
@Override
public void show() {
super.show();
avi.show();
}
@Override
public void dismiss() {
super.dismiss();
avi.hide();
}
}
Step 5:
加载框显示
LoadingDialog.getInstance(this).show();
加载框隐藏
LoadingDialog.getInstance(this).dismiss();
Step 6:
效果图
加载中.jpg