如何添加网页视图到具有更多小部件的布局 [英] How add a webview to a layout that have more widgets

查看:124
本文介绍了如何添加网页视图到具有更多小部件的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想网页视图添加到我的layout.But该布局具有一些其他部件also.But当我运行应用程序的WebView需要整个屏幕和其他部件得到disappear.here是我的布局page.xml ....

I want to add a webview to my layout.But that layout have few other widgets also.But when i run the application webview takes the entire screen and other widgets get disappear.here is my layout page.xml....

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" >

<WebView android:layout_width="match_parent" android:layout_height="200dp" android:id="@+id/web"></WebView>

<View   android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:layout_height="2px" android:background="#ffffff" android:layout_width="fill_parent" ></View>

<TextView android:text="Simple text view"  android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>


</LinearLayout>

和在活动类

    setContentView(R.layout.page);

    WebView wv1=(WebView)findViewById(R.id.web);
    wv1.loadUrl("http://google.com");

它不会显示视图和TextView的,但web视图得到整个screen.Please告诉我什么我做错了什么here.Or是正确的方式,我应该做的。
谢谢你。

It does not display the view and textView but webview get the entire screen.Please show me what i am doing wrong here.Or what is the correct way i should do. thank you.

推荐答案

尝试设置的 WebViewClient ,它会解决你的问题。

Try to set the WebViewClient, it will solve your problem.

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         WebView wv1=(WebView)findViewById(R.id.web1);
         wv1.setWebViewClient(new myClient());
         wv1.loadUrl("http://google.com");
    }

    class myClient extends WebViewClient
    {
        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            view.loadUrl(url);
            return true;
        }

        @Override
        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            // TODO Auto-generated method stub
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    }

这篇关于如何添加网页视图到具有更多小部件的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆