0

それぞれWebビューを含む2つの異なるアクティビティを切り替えようとしていました。それらを切り替えるときに多くのメモリの問題が発生し、次のことを試しています。同じレイアウトにVISIBLEまたはGONEの2つのWebビューを設定しました。webviewAからボタンを押すと、webviewBにURLが読み込まれ、webviewB onPageFinished()の場合、AはGONEに設定され、BはVISIBLEに設定されます。BからAまで同じです。問題は、URLが最初にのみロードされることです。

2つのWebビューは、次のように同じレイアウトに設定されます。

<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アクティビティ、

final 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);

webviewAボタンをクリックして、

webviewB.loadUrl(UrlVista);

次に、webviewBのonPageFinished()が起動され、

 webviewB.setWebViewClient(new WebViewClient() 
        {   
                    @Override
                    public void onPageFinished(WebView view, String url) 
                    {
                        LayoutA.setVisibility(View.GONE);
                        LayoutB.setVisibility(View.VISIBLE);
4

1 に答える 1

3

2 つの RelativeLayouts があります。1つは基本的にもう1つを画面から押し出しています。あなたが持っているものの代わりに、2 つの webviews を持つ相対レイアウトを 1 つだけ用意してください。

あなたのxmlファイルで:

<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"
        android:alignParentLeft="true"
        android:alignParentTop="true"//>

    <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"
        android:alignParentLeft="true"
        android:alignParentTop="true"/>

</RelativeLayout>

次に、あなたの onPageFinished で

webviewB.setWebViewClient(new WebViewClient(){
    @Override
    public void onPageFinished(WebView view, String url{                               
        webviewA.setVisibility(View.GONE);
        webviewB.setVisibility(View.VISIBLE);
    }
});

これにより、基本的に、レイアウトではなく WebView 自体の可視性を設定する必要があります。この場合のレイアウトは互いに重ねることができ、それらの可視性を使用して本質的にオンとオフを切り替えることができます。

于 2012-06-22T18:44:28.553 に答える