我正在开发一个使用 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/