自定义进度对话框动画

时间:2012-07-24 08:30:16

标签: android android-layout android-emulator android-widget

我正在研究Custom Progress Dialog。我已经在这个问题中设置了它的样式Positionning the spinning wheel in a custom progress dialog我的进度对话框根本没有显示任何动画。当我将background更改为black时,它只显示了一个黑盒子。我希望我的进度对话框能够生成动画。

在活动中,我正在做这样的事情

 public MyProgressDialog(Context context) {
        super(context, R.style.NewDialog);
    }

和NewDialog如下:

<style name="NewDialog" parent="@android:style/Theme.Dialog">

    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:width">50dip</item>
    <item name="android:height">50dip</item>
    <item name="android:background">@android:color/transparent</item>

</style>

提前感谢任何帮助

2 个答案:

答案 0 :(得分:11)

import android.app.ProgressDialog;
import android.content.Context;
import android.view.animation.Animation;

public class MyProgressDialog extends ProgressDialog {

    public MyProgressDialog(Context context) {
        super(context,R.style.NewDialog);

        // TODO Auto-generated constructor stub
    }

}

// RESOURCE STYLE FILE res-&gt; values-&gt; mydialog.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <style name="NewDialog" parent="@android:style/Theme.Dialog">

    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:colorBackground">#ffffff</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:width">600dip</item>
    <item name="android:height">100dip</item>
     <item name="android:textColor">#FF0000</item>

</style>
</resources>

//并在您的应用程序中使用此代码以获取定制进度对话

MyProgressDialog pd = new MyProgressDialog(YouActivity.this);
pd.setMessage("Loading. Please wait...");
pd.show();

你的代码和我的代码没有任何区别,因为我运行你的代码只是为了测试你是否遇到任何问题,但我仍在为你发帖,以便你可以找到问题所在。

谢谢:)

答案 1 :(得分:2)

public class TransparentProgressDialog extends Dialog {

 private ImageView iv;

 public TransparentProgressDialog(Context context, int resourceIdOfImage) {

     super(context, R.style.TransparentProgressDialog);
  WindowManager.LayoutParams wlmp = getWindow().getAttributes();
  wlmp.gravity = Gravity.CENTER_HORIZONTAL;
  getWindow().setAttributes(wlmp);
  setTitle(null);
   setCancelable(false);
   setOnCancelListener(null);
   resourceIdOfImage = R.drawable.loading_spinner_icon;
  LinearLayout layout = new LinearLayout(context);
   layout.setOrientation(LinearLayout.VERTICAL);
  LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
   LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  iv = new ImageView(context);
  iv.setImageResource(resourceIdOfImage);
  layout.addView(iv, params);
  addContentView(layout, params);
  }

  }

您将获得动画HERE

的完整示例