菊花加载动画
1.新建dialog类 设置大小和样式
context.requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
context.setCanceledOnTouchOutside(false);//点击空白处不消失
方法设置弹框大小
setWindowSize(25,25);//弹框大小
public void setWindowSize(int x,int y) {
Window window =context.getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.gravity = Gravity.CENTER;
params.width = SystemUtil.getScreenX() * x /100;
params.height = SystemUtil.getScreenX() * y /100;
context.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
}
dialog类
@SuppressLint("InflateParams")
public class LoadingDialogextends Dialog {
DialogUtilsdialogUtils;//弹框工具
public LoadingDialog(@NonNull Context context) {
super(context, R.style.MyDialogStyle);
initView();
}
private void initView() {
//设置弹框大小
dialogUtils =new DialogUtils(this);
dialogUtils.setDialogStyle();//初始化弹框
setContentView(R.layout.loading_dialog);
dialogUtils.setWindowSize(25,25);//弹框大小
}
}
MyDialogStyle
<!-- my loading dialog -->
<style name="MyDialogStyle">
<!--窗口背景透明-->
<item name="android:windowBackground">@android:color/transparent</item>
<!-- 是否有边框 -->
<item name="android:windowFrame">@null</item>
<!--标题 -->
<item name="android:windowNoTitle">true</item>
<!--是否在悬浮Activity之上 -->
<item name="android:windowIsFloating">true</item>
<!--阴影 -->
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<!--透明背景-->
<item name="android:background">@android:color/transparent</item>
<!--弹窗背景是否变暗-->
<item name="android:backgroundDimEnabled">false</item>
</style>
dialog布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="@drawable/loading_yj_bg_shape">
android:id="@+id/loading"
android:layout_width="32dp"
android:layout_height="32dp"
android:indeterminateBehavior="repeat"
android:indeterminateDrawable="@drawable/anim" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/white"
android:text="加载中..."
android:layout_marginTop="10dp"/>
</LinearLayout>
loading_yj_bg_shape.xml
anim.xml
最后就是new LoadingDialog()对象然后show就可以
网友评论