0
我試圖在兩個包含webview的不同活動之間切換。我在切換時遇到了很多內存問題,現在我正在嘗試以下方法:在同一個佈局中設置VISIBLE或GONE兩個WebView。 當我按下webviewA的一個按鈕時,在webviewB上加載一個url,當webviewB onPageFinished(),A被設置爲GONE並且B被設置爲VISIBLE時。從B到A的問題同樣是URL只加載第一次......設置在相同佈局上的webviews之間的android切換
2個網頁視圖是在相同的佈局等設定,
<RelativeLayout
android:id="@+id/aLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/barraSocial">
<WebView
android:id="@+id/webviewA"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:autoLink="web"
android:textColor="@android:color/black"
android:scrollbars="none"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/bLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/barraSocial">
<WebView
android:id="@+id/webviewB"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:autoLink="web"
android:textColor="@android:color/black"
android:scrollbars="none"/>
</RelativeLayout>
的onCreate活動,
上webviewAfinal RelativeLayout LayoutA = (RelativeLayout)findViewById(R.id.aLayout);
final RelativeLayout LayoutB = (RelativeLayout)findViewById(R.id.bLayout);
webviewA = (WebView) findViewById(R.id.webviewA);
webviewB = (WebView) findViewById(R.id.webviewB);
按一下按鈕,
webviewB.loadUrl(UrlVista);
然後,onPageFinished()從webviewB被激發,
webviewB.setWebViewClient(new WebViewClient()
{
@Override
public void onPageFinished(WebView view, String url)
{
LayoutA.setVisibility(View.GONE);
LayoutB.setVisibility(View.VISIBLE);
你有webview b按鈕點擊和webviewA.setWebViewClient實施? – trumpetlicks
是的,已經實施!與發佈相同,但從B到A – Jaume
當您說URL只是第一次加載時,是指初始化URL,還是第一次單擊按鈕後的URL?你也有2個相對的佈局與填充父母。第一個定義是贏。當你按下第一個按鈕,並且網址與新網站一起出現時,它甚至不在屏幕上! – trumpetlicks