2014-03-04 21 views
0

我不想指出我的webview是以某種方式加載的。使用Progressbar似乎是一個很好的解決方案,但我不確定如何正確執行此操作。 按進度條我的意思是Android中的旋轉thingie。如何在加載時正確顯示Webview的ProgressBar

這就是我現在知道的和我所嘗試的: 我知道您在WebViewClient內部定義的onPageStarted(...)和onPageFinished(...)回調,然後根據調用隱藏或顯示Progressbar到那些方法。但是這種方法會在w​​ebview中的HTML頁面上產生很多問題。例如,當我隱藏Progressbar HTML元素時調整大小,並在短時間內恢復原始大小。這看起來非常難看,我不知道爲什麼會發生這種情況。我試着把框架和相對佈局中的進度條和web視圖放在一起(爲了讓進度變得易怒),並且這兩個都得到了上述問題。加載HTML頁面是JavaScript重的,因爲它有http://cubiq.org/iscroll-4庫,但我懷疑它是庫的問題,因爲在手機上的瀏覽器應用程序中打開時,同一頁加載時沒有奇怪的行爲。

我的主要問題是我不知道如何定義包含我的Progressbar和webview的佈局,並避免奇怪的放大/縮小跳轉。這就是爲什麼我問如何在Web視圖上正確顯示進度條。

編輯: 這是我試過的佈局之一:設計

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

<WebView 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 

<ProgressBar 
    android:id="@+id/progressBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" /> 

</FrameLayout> 

它更或相對佈局不太相似,但我用centerInPerent =真兩軸的進度

+0

您可以發佈您的佈局XML中的進度條的知名度? – Decoy

+0

將在幾分鐘內將其添加到EDIT中。查看編輯。 – PSIXO

回答

0

的FrameLayout屏蔽屏幕上的區域以顯示單個項目。一般來說,應該使用FrameLayout來保存一個子視圖。

我會用的RelativeLayout:

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

<WebView 
    android:id="@+id/webview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<ProgressBar 
    android:id="@+id/progressBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:centerInParent="true" /> 

</RelativeLayout> 

這應該工作...

+0

感謝您的信息。是不是FrameLayout推薦的方式來分層佈局(一個元素在另一個元素上)?你展示的這個相對佈局正是我嘗試過的另一個,但它也給了我奇怪的放大/縮小錯誤。我應該如何在這個佈局中隱藏ProgressBar,使用GONE或INVISIBLE我嘗試了兩種,但仍然遇到縮放bug,但我可能錯過了某些東西? – PSIXO

1

有顯示在活動進程的有效途徑。如果您使用的是ActionBar,則可以使用 ,您可以設置INDETERMINATE進度條(旋轉的進度條)或水平進度條(如在Chrome瀏覽器中看到的那樣)。要做到這一點,你必須到窗口功能設置爲像適當的值:

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 

OR

requestWindowFeature(Window.FEATURE_PROGRESS); 

要設置的進度值,這樣做:

setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 

然後調用setProgress(int)每當你想改變進度值。

您可以使用CONTROLL

setProgressBarIndeterminateVisibility(true); //sets it to visible 

setProgressBarIndeterminateVisibility(false); //hides the progressbar 
+0

感謝您提供有關此其他方法的信息。不幸的是,我不能在當前的項目中使用它,但它可能會在未來發現它。 – PSIXO

相關問題