android – 居中自定义进度对话框

我创建了一个Custom ProgressDialog,如下所示:
首先,我有一个包含9个连续Imges的动画列表

<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="@drawable/icon_progress_dialog_drawable_1" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_2" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_3" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_4" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_5" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_6" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_7" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_8" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_9" android:duration="150" />

然后我有一个自定义的风格

 <style name="CustomDialog" parent="@android:style/Theme.Dialog" >
    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>      
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:gravity">center</item>
    <item name="android:minHeight">70dip</item>
    <item name="android:maxHeight">80dip</item>       

现在在代码中我将其称为如下

 dialog = new ProgressDialog(KaguaHome.this); 
        dialog.setProgressStyle(R.style.CustomDialog);
        dialog.setIndeterminate(true);
        dialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress_dialog_icon_drawable_animation));
        dialog.show();

结果是

然而,我想要只用图像(没有白色背景)来实现进度对话框,它应该居中,我应该修改什么?

解决方法:

试试这个并说出它是如何工作的.我试过这个,对我而言它就是中心.

<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:background">@android:color/transparent</item>
        <item ame="android:indeterminateDrawable">@anim/progress_dialog_icon_drawable_animation</item>
    </style>

并声明为

customDialog = new Dialog(getActivity(),R.style.NewDialog);

看看这是否有效.

上一篇:android ProgressDialog fontSize更改


下一篇:AsyncTask的进度对话 – Android