Webビューを含むアプリケーションを開発しています。私はRelativeLayout
xmlファイルのルート要素として持っています。RelativeLayout
たProgressBar
、SwipeRefreshLayout
、WebView
およびAdView
要素が含まれています。デフォルトでは、の可視性ProgressBar
はに設定されてgone
おり、Webページの読み込み中に表示され、再び非表示になります。しかし、それはいつでも表示されていません。これが私の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>
とプロパティを使用LinearLayout
してみましたが、が表示されますが、消えます。LinearLayoutを使用したコードは次のとおりですweight
weightsum
ProgressBar
AdView
<?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>
この問題について私を助けてください。私は両方欲しいProgressBar
とAdView
。私が作っていますProgressBar
に表示Siteview.java
中のファイルonCreate
の方法。以下はコードです
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の可視性を非表示に設定し、プログレスバーが表示されていないときにSwipeRefreshLayoutを表示することができます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加