0
我創建了一個包含兩個webView並排的簡單活動。我使用下面的代碼來啓動它們。您可以在Android的同一活動中同時運行兩個webView嗎?
setContentView(R.layout.detail); //xml layout that contains two webviews
webView1 = (WebView) this.findViewById(R.id.webView1);
webView2 = (WebView) this.findViewById(R.id.webView2);
webView1.setWebChromeClient(new WebChromeClient());
webView1.loadUrl("http://www.google.com");
webView2.setWebChromeClient(new WebChromeClient());
webView2.loadUrl("http://www.google.com");
的問題是,與上面的代碼webView1加載罰款而webView2始終是空白的(只是一個白框),我不明白爲什麼。
這裏是我的xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip" >
<WebView
android:id="@+id/webView2"
android:layout_width="470dp"
android:layout_height="300dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
<WebView
android:id="@+id/webView1"
android:layout_width="470dp"
android:layout_height="300dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/webView1"
android:layout_alignParentTop="true"
android:layout_marginTop="49dp"
android:text="Cell"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/TextView01"
android:layout_alignParentLeft="true"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_marginLeft="50dp"
android:layout_toRightOf="@+id/textView2"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/TextView01"
android:layout_alignLeft="@+id/TextView01"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/webView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="23dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
它們不是彼此之上嗎?你的屏幕有多大? – njzk2
沒有它的聯繫7,它們並排,屏幕寬度大於1000dp。 – stackdaddy
如果不在webView1中加載url,會發生什麼情況? – njzk2