开发者

How I hide a WebView?

开发者 https://www.devze.com 2023-01-23 12:06 出处:网络
I 开发者_C百科need to hide a WebVew while it is loading its web content. I tried to do it with other view like this:

I 开发者_C百科need to hide a WebVew while it is loading its web content. I tried to do it with other view like this:

<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 the View doesn't cover the WebView and it doesn't hide. I need to put the view on the front while the WebView is loading.


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

If it's LinearLayout no wonder that View doesn't cover WebView. If you want to user Layouts, try using RelativeLayout and aligning elements identically, for example, adding to both views:

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

Another variant (and more correct IMO) is to use ViewSwitcher, or ViewFlipper. It switches between it's children with showNext(), showPrevious() (in ViewFlipper) and getNextView() (in ViewSwitcher) methods. Really easy to implement and use. Look up some examples.

Just a quick tip:

<!-- 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>

And, in your code:

// 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();

The difference between the two, is that Switcher can only have 2 children, and has a factory for view creation.

P.S. Mixed two animators, edited post.

0

精彩评论

暂无评论...
验证码 换一张
取 消