gpt4 book ai didi

java - 进度条未显示在 webview 的 Relativelayout 中

转载 作者:行者123 更新时间:2023-11-29 18:50:42 25 4
gpt4 key购买 nike

我正在开发一个包含 WebView 的应用程序。我将 RelativeLayout 作为 xml 文件的根元素。 RelativeLayout 包含 ProgressBarSwipeRefreshLayoutWebViewAdView 元素。默认情况下,ProgressBar 的可见性设置为 gone,它应该在加载网页时出现,然后再次隐藏。但是,它不会随时显示。这是我的 activity_web_view.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.softglobe.allmedia.Showsite"
android:orientation="vertical">

<ProgressBar
android:id="@+id/pb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="@drawable/progressbar_states"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:visibility="gone"/>


<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
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:configChanges="orientation|screenSize"/>

</android.support.v4.widget.SwipeRefreshLayout>

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
android:layout_alignBottom="@id/swiperefresh"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>

我尝试将 LinearLayoutweightweightsum 属性一起使用,然后显示 ProgressBar,但随后 AdView 消失。使用LinearLayout的代码如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.softglobe.allmedia.Showsite"
android:orientation="vertical"
android:weightSum="20">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" >

<ProgressBar
android:id="@+id/pb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="@drawable/progressbar_states"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:visibility="gone"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="18"
android:orientation="horizontal" >

<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
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:configChanges="orientation|screenSize"/>

</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2" >

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
android:layout_alignBottom="@id/swiperefresh"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</LinearLayout>

请帮我解决这个问题。我想要 ProgressBarAdView。我在 onCreate 方法中使 ProgressBarSiteview.java 文件中可见。以下是代码

 final SwipeRefreshLayout finalMySwipeRefreshLayout1 = mySwipeRefreshLayout;
myWebView.setWebViewClient(new WebViewClient() {

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {

// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
// Visible the progressbar
mProgressBar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
finalMySwipeRefreshLayout1.setRefreshing(false);
}
});

最佳答案

您的 SwipeRefreshLayout 位于 ProgressBar 之上,因此即使您使 ProgressBar 可见,它也会显示在 SwipeRefreshLayout 下方,您将看不到它,您可以使用

 `android:layout_below="@+id/pb"`

在您的 SwipeRefreshLayout 中,或者您可以在进度条可见时将 SwipeRefreshLayout 可见性设置为消失,并在 ProgressBar 不可见时将 SwipeRefreshLayout 设置为可见。

关于java - 进度条未显示在 webview 的 Relativelayout 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50999810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com