与webview放在一起时,进度条不可见

时间:2012-03-09 13:36:06

标签: android webview progress-bar

LinearLayout中有一个WebViewProgressBar元素。

WebView是全屏。

我尝试在ProgressBar加载某些内容时显示WebView

但似乎ProgressBar涵盖WebView因此不可见。

如果我将WebView设为隐身,我可以看到ProgressBar

那么如何在ProgressBar

之上显示WebView

4 个答案:

答案 0 :(得分:5)

尝试使用RelativeLayout而不是LinearLayout。将WebView作为第一个子项,将ProgressBar作为第二个子项,这将使ProgressBar位于WebView的顶部。

答案 1 :(得分: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>

答案 2 :(得分:0)

您可以在ProgressBar中使用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

答案 3 :(得分:0)

更好的方法+即使滚动浏览WebView,progressBar也会保留在屏幕上:将进度条放在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>