【发布时间】:2017-05-25 21:52:21
【问题描述】:
我正在尝试制作一个自定义 ProgressBar 类,我想在其中显示一个带有图像旋转的 ProgressBar。
我尝试的是......
my_progress_indeterminate.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/spool"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="1080">
</rotate>
MyProgress.java
public class MyProgress extends ProgressDialog {
//private AnimationDrawable animation;
ProgressBar la;
public ProgressDialog ctor(Context context) {
MyProgress dialog = new MyProgress(context);
dialog.setIndeterminate(true);
dialog.setIndeterminateDrawable(this.getContext().getResources().getDrawable(R.drawable.my_progress_indeterminate));
dialog.setCancelable(false);
return dialog;
}
public MyProgress(Context context) {
super(context);
}
public MyProgress(Context context, int theme) {
super(context, theme);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_loader);
la = (ProgressBar) findViewById(R.id.animation);
}
@Override
public void show() {
super.show();
//show the progressbar which is rotating image
}
@Override
public void dismiss() {
super.dismiss();
//hide the progress which is rotating image
}
}
在我想展示进度的其他课程中,我正在这样做:
MyProgress rotateImage;
protateImage = new MyProgress(getActivity());
protateImage.show(); //for showing
protateImage.hide(); //for hiding
ViewLoader.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@null"
>
<ProgressBar
android:id="@+id/animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dip"
android:indeterminateDrawable="@drawable/my_progress_indeterminate" />
</LinearLayout>
它运作良好,但我无法看到我的图像旋转, 仅显示 androids 自定义进度条旋转样式,带有对话框背景。
我想要的是通过创建我的类的实例并显示进度条(旋转图像)或隐藏它来仅显示我的图像在我的项目中的任何位置旋转...
我怎样才能使它正确?任何帮助...
【问题讨论】:
-
能把view_loader.xml和animation.xml的内容也贴一下吗?
-
检查我编辑问题提供的视图 loader.xml 文件
标签: java android progress-bar progressdialog