带有relativelayout的android webview和进度条

标签 android webview

我正在开发一个使用 webview 显示网站的简单 android 应用程序,我正在尝试在 webview 顶部添加进度条。如果我使用 LinearLayout,这会很好用,但我想使用 relativelayout 添加进度条,因为当我使用 admobe 时效果更好。

问题是当我使用 relativelayout 时进度条消失了。

这是我的代码:

 <RelativeLayout  
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ads="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">



 <ProgressBar
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progressbar_Horizontal"
android:max="100"
android:background="#228b22"
/>

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


  </LinearLayout >

最佳答案

问题是:您的 WebView 的 layout_height="fill_parent"占据了整个屏幕的高度

尝试像这样放置 View :

<RelativeLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ProgressBar
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        style="?android:attr/progressBarStyleHorizontal"
        android:id="@+id/progressbar_Horizontal"
        android:max="100"
        android:background="#228b22"
    />

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:layout_below="@id/progressbar_Horizontal"/>

</RelativeLayout>

这样,WebView 就会放在 ProgressBar 的下面,你的 ProgressBar 就不会重叠。

希望这对您有所帮助。

关于带有relativelayout的android webview和进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27444460/

相关文章:

android 客户端中的 java.io.StreamCorrupted Exception`

android - BufferedReader,读了多少字节?

android - 简单的 9 补丁图像拉伸(stretch)不正确,在高分辨率设备上获得 1px 边框

android - 如何保留之前加载的图像?

Android:在 web View 中读取具有 ISO-8859-1 字符编码的文本文件

javascript - 在 WKWebView iOS 中加载本地 React 应用程序

android - 在framelayout中添加两个webview

android - 如何在android webView中获取WebResourceRequest的主体

webview - 如何从 dart 中的 JSObjects 获取所有属性和方法的列表

Android:减小微调器下拉框的宽度