2012-03-09 59 views
0

LinearLayout中有WebViewProgressBar元素。當與webview一起放置時,進度條不可見

WebView是全屏顯示。

而我試圖顯示ProgressBarWebView正在加載的東西。

但似乎ProgressBarWebView涵蓋,因此不可見。

如果我設置WebView爲隱形,我可以看到ProgressBar

那麼如何在WebView的頂部顯示ProgressBar

回答

5

嘗試使用RelativeLayout而不是LinearLayout。將WebView作爲第一個孩子,將ProgressBar作爲第二個孩子,這會將ProgressBar放在WebView的頂部。

+0

按'頂部'我的意思是我希望ProgressBar在web視圖上有一個z-index。 – 2012-03-09 13:41:45

+0

是的,順序視圖被添加到一個RelativeLayout中定義了它們的z順序。 – 2012-03-09 13:44:02

+0

+1同意答案。 – 2012-03-09 13:44:17

2

你應該使用RelativeLayout來做到這一點。這將是這樣的:

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

    <WebView 
     android:id="@+id/webView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" /> 

    <ProgressBar 
     android:id="@+id/progressBar1" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 
0

可以使用Android:translationZ屬性在進度:

<ProgressBar 
    android:id="@+id/progress_bar" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:translationZ="2dp" 
    android:layout_centerInParent="true"/> 

和使用RelativeLayout

More information

0

更好的辦法+進度條將保持在你的屏幕上,即使當你滾動瀏覽WebView時:將進度條放在FrameLayout和WebView下面......

<RelativeLayout 
    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" 
     android:layout_centerVertical="true" 
     /> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="150dp"> 

      <ProgressBar 
       <!-- your progress bar here--> 
      /> 

     </FrameLayout> 
</RelativeLayout>