2014-09-22 91 views
0

我想在Android應用程序中同時顯示2個WebViews。我想知道這是否可能,因爲我還沒有遇到過這樣的應用程序。如果有什麼方法可以告訴我如何去做?顯示多個網頁瀏覽

回答

0
 make you xml like below 

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context=".MainActivity" > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:weightSum="2" > 

       <WebView 
        android:id="@+id/web1" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" /> 

       <WebView 
        android:id="@+id/web2" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" /> 
      </LinearLayout> 


     </RelativeLayout> 


     write you activity below code 


       WebView webView1 = (WebView)findViewById(R.id.web1); 
       WebView webView2 = (WebView)findViewById(R.id.web2); 

       WebSettings settings1 = webView1.getSettings(); 
       WebSettings settings2 = webView2.getSettings(); 
       settings1.setJavaScriptEnabled(true); 
       settings2.setJavaScriptEnabled(true); 
       webView1.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 
       webView1.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 

       webView1.loadUrl("www.google.co.in"); 
       webView2.loadUrl("http://stackoverflow.com/");