【发布时间】:2020-01-21 11:55:48
【问题描述】:
我的进度条在某些设备上无法正常工作 like here 并按预期工作 like here 这是original file
的
如果有人对在进度条上使用 gif 文件有更好的想法,请与我分享。
.java
public static void displayProgressDialog(Context context, boolean cancellable) {
ImageView imageView;
if (context == null || (context instanceof AppCompatActivity && ((AppCompatActivity) context).isFinishing()))
return;
if (cancellable) {
if (context instanceof AppCompatActivity && view == null) {
AppCompatActivity activity = (AppCompatActivity) context;
view = activity.getLayoutInflater().inflate(R.layout.layout_dialog_loading, null);
ViewGroup.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
activity.addContentView(view, params);
}
} else {
if (progressDialog != null) return;
progressDialog = new AlertDialog.Builder(context, R.style.MyTheme).create();
FrameLayout f1 = new FrameLayout(context);
progressDialog.setView(f1);
progressDialog.getLayoutInflater().inflate(R.layout.layout_dialog_loading, f1);
progressDialog.setCancelable(false);
// progressDialog.setIndeterminate(false);
// progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.show();
}
}
xml
<?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:orientation="horizontal">
<ProgressBar
android:id="@+id/progress"
android:indeterminate="true"
android:indeterminateTint="@color/bgColorDefault"
android:indeterminateDrawable="@drawable/myprogress_interminate"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
旋转
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/animation"
android:pivotX="50%"
android:pivotY="50%" />
动画终于来了
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1"
android:toDegrees="360"
android:drawable="@drawable/spinnerinstacare">
</rotate>
【问题讨论】:
标签: android progress-bar gif