2017-08-10 40 views
0

在滚动视图中有两个网页浏览。Nest ScrollView

<ScrollView> 
<LinearLayout> 
<WebView></WebView> 
<WebView></WebView> 
</LinearLayout> 
</ScrollView> 

我想让两个webviews看起来像一个网页。目前,我的解决方案是使webview的高度等于webview的contentHeight。并禁用webview的可滚动性。但对于非常大的HTML。这不是一个好的解决方案。 webview必须呈现整个html。我想使用nestedscrollview。使两个webviews的高度等于nestedscrollview的高度。但我不知道如何处理这些事件。

+1

但为什么要使用2个网页视图? –

+0

@ IonutJ.Bejan,因为有两个网页来自不同的网站 – WhatisThat

+0

@WhatisThat尝试我的下面的答案 – akhilesh0707

回答

2

尝试使两个WebView看起来像一个网页。

public class MainActivity extends Activity { 

    String url = "http://www.yahoo.com"; 
    String url1 = "http://www.google.com"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Log.d("MainActivity", "Activity one"); 

     WebView webview = (WebView) findViewById(R.id.webView1); 
     webview.getSettings().setJavaScriptEnabled(true); 
     webview.setWebViewClient(new WebViewController()); 
     webview.loadUrl(url); 

     WebView webview2 = (WebView) findViewById(R.id.webView2); 
     webview2.getSettings().setJavaScriptEnabled(true); 
     webview2.setWebViewClient(new WebViewController()); 
     webview2.loadUrl(url1); 

    } 
} 

XML代码

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

      <WebView 
       android:id="@+id/webView1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

      <WebView 
       android:id="@+id/webView2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

     </LinearLayout> 

    </android.support.v4.widget.NestedScrollView> 

</LinearLayout> 

的WebView客户

class WebViewController extends WebViewClient { 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     view.loadUrl(url); 
     return true; 
    } 
}