软工超越日报-Android显示通知框 5/1

网络通信时经常需要加载动画,那么今天我们来做一个显示加载弹框的dialog吧

java调用代码如下:

Dialog dialogs = new Dialog(this, R.style.DialogTheme);
        LayoutInflater inflaters = LayoutInflater.from(this);
        View viewDialogs = inflaters.inflate(R.layout.loading, null);
        int width = 1000;
        int height = 300;
        ViewGroup.LayoutParams layoutParamss = new  ViewGroup.LayoutParams(width, height);
        dialogs.setContentView(viewDialogs, layoutParamss);
        dialogs.setCanceledOnTouchOutside(false);
        dialogs.setCancelable(false);
        dialogs.findViewById(R.id.icos).setAnimation(rotate);
        dialogs.findViewById(R.id.icos).startAnimation(rotate);
        dialogs.show();

layout文件如下:

<?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="105sp"
    android:orientation="horizontal"
    android:padding="15sp">

    <ImageView
        android:id="@+id/icos"
        android:layout_width="85sp"
        android:layout_height="match_parent"
        android:src="@drawable/icon"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="正在同步数据......"
        android:textSize="20sp"
        android:gravity="center"
        />

</LinearLayout>

具体实现效果如下:

原文地址:https://www.cnblogs.com/Sakuraba/p/14910387.html