自定义等待进度条实现

xml

ProgressBar
<ProgressBar
android:id="@+id/progress"
android:layout_width="30dp"
android:layout_height="30dp"
android:indeterminateBehavior="repeat"//重复
android:layout_gravity="center"
android:indeterminateDrawable="@drawable/top_loading_progress"
android:indeterminateOnly="true"//是否确定进度值
android:visibility="gone" />
圆环
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="3"//内环的半径比率  默认9
android:shape="ring"        //环的宽度除以Ratio
android:thicknessRatio="24"//环的厚度比率   默认3
android:useLevel="false" >
<gradient
android:centerY="0.50"
android:endColor="#ff6699"
android:startColor="#0affaaff"
android:type="sweep"//扫描式渐变
android:useLevel="false" />
shape>
旋转
  1. wait for test

<set
xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:duration="200"
android:fromDegrees="180.0"
android:toDegrees="0.0" 
android:pivotX="50.0%"
android:pivotY="50.0%" />
set>
  1. animated-rotate

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress_shape_new"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="359" />

java

1.自定义对话框

public class CustomProgressDialog extends Dialog {
    private Context context = null;
    private static CustomProgressDialog customProgressDialog = null;

    public CustomProgressDialog(Context context) {
        super(context);
        this.context = context;
    }

    public CustomProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    //点击空白部分隐藏进度条
        setCanceledOnTouchOutside(false);
        super.onCreate(savedInstanceState);
    }

    public static CustomProgressDialog createDialog(Context context) {
        customProgressDialog = new CustomProgressDialog(context,
                R.style.CustomProgressDialog);
        customProgressDialog.setContentView(R.layout.customprogressdialog);
        customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        return customProgressDialog;
    }

    public void onWindowFocusChanged(boolean hasFocus) {

        if (customProgressDialog == null) {
            return;
        }
    }
}

你可能感兴趣的:(Android)