0
我想制作一个自定义ProgressBar类,我想在其中显示带图像旋转的ProgressBar。在任何类中动态显示Android自定义ProgressBar或ProgressDialog
我试过了...
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>
它运作良好,但我看不到我的图像旋转, 只有机器人定制进度纺纱风格所示,用对话的背景。
我要的是通过创建我的类的实例,并显示进度条(旋转图像)或隐藏它,只显示我的形象在我的项目的任何位置旋转......
我怎样才能使它正确吗?任何帮助...
你还可以发布view_loader.xml和animation.xml的内容吗? –
检查我编辑问题提供的视图loader.xml文件 – user6768912