2011-11-04 93 views
0

我想將webview添加到我的layout.But該佈局也有其他窗口小部件。但是,當我運行應用程序時,webview將整個屏幕和其他窗口小部件消失。這裏是我的佈局page.xml ....如何將webview添加到具有更多窗口小部件的佈局

<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告訴我什麼我我在這裏做錯了什麼,或者我應該做的正確方法是什麼。 謝謝。

+1

在這裏你可以找到答案http://stackoverflow.com/questions/3382188/how-to-set-webview-as-non-fullscreen –

+0

感謝侯賽因,我認爲重定向使問題作爲CommonsWare說那裏。 google.com重定向到google.lk,然後瀏覽器讓我發瘋。 – sampathpremarathna

回答

1

試着設置WebViewClient,它會解決你的問題。你這樣的XML,那麼你的TextView VILL將在鈕所示,視圖將TextView的上方顯示

/** 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); 
     } 
    } 
0

變化,web視圖將在剩下的SPase顯示。

<RelativeLayout 
    ... 
> 
<TextView 
    android:layout_alignParentBottom="true" 
    android:id="@+id/sample_text" 
    ... 
/> 
<View 
    android:layout_above="@id/sample_text" 
    android:id="@+id/sample_view" 
    ... 
> 
<WebView 
    android:layout_above="@id/sample_view" 
    ... 
/> 
</RelativeLayout> 
相關問題