Java progressbar未在webview的Relativelayout中显示
我正在开发一个包含webview的应用程序。我将Java progressbar未在webview的Relativelayout中显示,java,android,webview,android-progressbar,Java,Android,Webview,Android Progressbar,我正在开发一个包含webview的应用程序。我将RelativeLayout作为xml文件的根元素。RelativeLayout包含ProgressBar、SwipeRefreshLayout、WebView和AdView元素。默认情况下,ProgressBar的可见性设置为gone,它应该在加载网页时出现,并且再次不可见。但是,它不会在任何时候出现。这是我的activity\u web\u view.xml <?xml version="1.0" encoding="utf-8"?>
RelativeLayout
作为xml文件的根元素。RelativeLayout
包含ProgressBar
、SwipeRefreshLayout
、WebView
和AdView
元素。默认情况下,ProgressBar
的可见性设置为gone
,它应该在加载网页时出现,并且再次不可见。但是,它不会在任何时候出现。这是我的activity\u web\u 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>
请帮我解决这个问题。我想要ProgressBar
和AdView
。
我正在使用onCreate
方法,使Siteview.java
文件中的ProgressBar
可见。下面是代码
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);
}
});
按如下方式重写这两个函数
<?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>
@Override
public void onPageStarted(String url, Bitmap favicon) {
pb.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(String url) {
pb.setVisibility(View.GONE);
}
您的SwiperFreshLayout位于ProgressBar的顶部,因此即使您使ProgressBar可见,它也会显示在SwiperFreshLayout下,您将无法看到它,您也可以使用
`android:layout_below="@+id/pb"`
在SwipeRefreshLayout中,或者,当进度条可见时,您可以将SwipeRefreshLayout可见性设置为“消失”,当进度条不可见时,您可以将SwipeRefreshLayout设置为“可见”。将代码粘贴到您试图看到进度的位置bar@vikassingh我已经添加了代码snippet@AnisurRahmanTonu不走运,请尝试删除这一行super.onPageStarted(视图、url、favicon);通过在
SwipeRefreshLayout