[英]Android: How to Create a Modal Progress “Wheel” Overlay?
我想在我的視圖上顯示一個模態進度“輪”覆蓋。
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 代碼相同)。
不確定是否有更好的方法,但您可以通過使用ProgressBar並將其設置為相互確定來自行獲得微調輪。 如果您使用的是AbsoluteLayout ,則可以將其放在其他視圖上。 此布局應使用 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>
為了在變暗的背景上創建全屏進度,我使用 FrameLayout 並在需要時將 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>
Klarth 的解決方案對我有用,謝謝!
在我的例子中,我使用 layout_gravity 來放置 progress_indicator 的中心位置,而不是使用顯式坐標。
<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"
/>
你檢查過這個教程嗎? 在頁面的末尾,它討論了如何創建自定義對話框,這可能會幫助您使用自己的背景放置一個微調進度對話框。
你只需添加.setCanceledOnTouchOutside(false);
到您的 ProgressDialog。
ProgressDialog dialog = new ProgressDialog(getApplicationContext());
dialog.setMessage("your message...");
dialog.setIndeterminate(true);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.