Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:如何创建模式进度;车轮“;覆盖层?_Android_Progressdialog - Fatal编程技术网

Android 安卓:如何创建模式进度;车轮“;覆盖层?

Android 安卓:如何创建模式进度;车轮“;覆盖层?,android,progressdialog,Android,Progressdialog,我想在我的视图上显示一个模式进度“轮子”覆盖图 ProgressDialog很接近,但我不想要对话框背景或边框 我尝试设置对话框窗口的背景可绘制: this.progressDialog = new ProgressDialog(Main.this); this.progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0)); this.progressDialog.setProgressStyle(Progress

我想在我的视图上显示一个模式进度“轮子”覆盖图

ProgressDialog很接近,但我不想要对话框背景或边框

我尝试设置对话框窗口的背景可绘制:

this.progressDialog = new ProgressDialog(Main.this);

this.progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
this.progressDialog.setCancelable(false);
this.progressDialog.setIndeterminate(true);

this.progressDialog.show();

但是没有用(也就是说,看起来仍然与没有…setBackgroundDrawable代码的情况相同)。

您检查过这个吗?在本页末尾,它讨论了如何创建自定义对话框,这可能有助于您放置具有自己背景的微调器进度对话框。

不确定是否有更好的方法,但您可以通过使用微调器并将其设置为interdeterminate来自行获得微调器控制盘。如果您使用的是视图,则可以将其置于其他视图之上。此布局应使用XML演示此方法:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/AbsoluteLayout"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ProgressBar android:id="@+id/ProgressBar"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:indeterminate="true" android:indeterminateOnly="true"
        android:isScrollContainer="true" android:layout_x="100dip"
        android:layout_y="10dip" android:soundEffectsEnabled="true"></ProgressBar>
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello"
        android:layout_gravity="center_horizontal" android:gravity="center_horizontal"
        android:layout_y="25dip" />
</AbsoluteLayout>

Klarth的解决方案对我很有效,谢谢

在我的例子中,我使用布局重力作为进度指示器的中心位置,而不是使用显式坐标

    <ProgressBar android:id="@+id/pb"
        android:layout_width="40dp" 
        android:layout_height="40dp"
        android:indeterminate="true" 
        android:indeterminateOnly="true"
        android:isScrollContainer="true" 
        android:layout_gravity="center_vertical|center_horizontal"
        android:soundEffectsEnabled="false"
        />

为了在深色背景上创建全屏进度,我使用框架布局,并在需要时将RelativeLayout的可见性设置为VISIBLE,或在长时间操作完成后将其设置为GONE:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:orientation="vertical"
        android:padding="3dip" >

            <!-- Your regular UI here -->

    </LinearLayout>
   </ScrollView>

   <RelativeLayout
       android:id="@+id/relativelayout_progress"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:visibility="gone"
       android:background="#aa000022" >

       <ProgressBar 
           android:layout_centerInParent="true"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:indeterminateOnly="true" />

    </RelativeLayout>
</FrameLayout>

您只需添加
.setCanceledOnTouchOut(false)到您的ProgressDialog

 ProgressDialog dialog = new ProgressDialog(getApplicationContext());
 dialog.setMessage("your message...");
 dialog.setIndeterminate(true);
 dialog.setCanceledOnTouchOutside(false);
 dialog.show();

谢谢,我相信这也行得通,所以我投了赞成票,但我选择了另一种解决方案,因为它更容易实现。只适用于对这个问题不熟悉的每个人。自API级别3以来,AbsoluteLayout已被弃用。这对你们来说意味着什么。因为AbsoluteLayout是去润滑的,所以使用FrameLayout将事物放置在彼此的顶部,就像EZDsIt的答案一样。也许应该重新选择正确的答案,似乎选择的是jsut,但作为教程的指针,每个人都投票的那个有一个更好的例子。我真的很喜欢这个想法,很容易实现。我只是建议在返回true的RelativeLayout中添加一个
OnTouchEventListener
,这样您的触摸事件就不会传递到底层的FrameLayout。另一个解决方案是让FrameLayout
android:clickable=“true”
对于那些想知道为什么这个答案没有多少向上投票的人来说,可能是这样的:注意:Android包含另一个名为ProgressDialog的对话框类,它显示一个带有进度条的对话框。此小部件已被弃用,因为它阻止用户在显示进度时与应用程序交互。“您应该使用下一个答案并将其包含在布局中。