我正在開發一個包含webview的應用程序。我有RelativeLayoutxml文件的根元素。的RelativeLayout已ProgressBar,SwipeRefreshLayout,WebView和AdView包含元素。默認情況下,的可見性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>我嘗試使用LinearLayoutwithweight和weightsum屬性,然后ProgressBar顯示,但是AdView消失了。
2 回答

拉風的咖菲貓
TA貢獻1995條經驗 獲得超2個贊
您的SwipeRefreshLayout位于ProgressBar的頂部,因此,即使使您的ProgressBar可見,它也將顯示在SwipeRefreshLayout下,并且您將無法看到它,您可以使用
`android:layout_below="@+id/pb"`
在您的SwipeRefreshLayout中,也可以在進度條可見時將SwipeRefreshLayout可見性設置為走,而在ProgressBar不可見時將SwipeRefreshLayout可見性設置為不可見。

陪伴而非守候
TA貢獻1757條經驗 獲得超8個贊
覆蓋這兩個功能如下
@Override
public void onPageStarted(String url, Bitmap favicon) {
pb.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(String url) {
pb.setVisibility(View.GONE);
}
添加回答
舉報
0/150
提交
取消