How do I hide a webview?

I need to hide WebVew when loading its web content. I tried to do this with a different view as follows:

<WebView
    android:scrollbars="none" 
    android:id="@+id/id_webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

<View
    android:visibility="gone"
    android:scrollbars="none" 
    android:id="@+id/id_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

When I want to hide the WebView, I change the visibility of the view to "visible" (View.setVisibility (View.VISIBLE);). But View does not cover WebView, and it does not hide. I need to put the view on the front while loading a WebView.

+3
source share
1 answer

Although I find this approach strange, you should check the parent container of these views.

LinearLayout , View WebView. , RelativeLayout , , :

android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"

( IMO) - ViewSwitcher ViewFlipper. showNext(), showPrevious() ( ViewFlipper) getNextView() ( ViewSwitcher). . .

:

<!-- ViewSwitcher or ViewFlipper -->
<ViewSwitcher

    android:id="@+id/view_switcher"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <View
        android:scrollbars="none" 
        android:id="@+id/id_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <WebView
        android:scrollbars="none" 
        android:id="@+id/id_webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</ViewSwitcher>

:

// This will hide currently displayed and reveal next
((ViewSwitcher) findViewById(R.id.view_switcher)).getNextView(); 

// Or, in case of ViewFlipper:
// This will hide currently displayed and reveal next
((ViewFlipper) findViewById(R.id.view_switcher)).showNext();

, Switcher 2 factory .

P.S. , .

+6

Source: https://habr.com/ru/post/1772828/


All Articles