[Android]实现WebView浏览器多标签浏览功能的关键

我在开发过程中碰到这个问题,网上搜索了下,百度谷歌都翻了十几页依旧无果。似乎大家都藏着不愿意说,又或者太简单不屑于提。

我在这里简单提一下我的做法(纯粹是抛砖引玉,可能有更加完善更加标准的解决方案,但我搜索不到):

首先,WebView是viewgroup的孙子类。

viewgroup在显示时有个关键方法:onlayout 这是个抽象方法

然后去webview的父类中找这个方法,代码如下:

@Override
    protected void onLayout(boolean changed, int l, int t,
            int r, int b) {
        int count = getChildCount();

        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            if (child.getVisibility() != GONE) {

                AbsoluteLayout.LayoutParams lp =
                        (AbsoluteLayout.LayoutParams) child.getLayoutParams();

                int childLeft = mPaddingLeft + lp.x;
                int childTop = mPaddingTop + lp.y;
                child.layout(childLeft, childTop,
                        childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());

            }
        }
    }

 

================伸手党看这里=======================

可以看到只需将不显示的页面visibility设为gone,就可以了。

posted on 2013-02-09 08:23  B1ncer  阅读(1679)  评论(2编辑  收藏  举报

导航