Android 在安卓系统中,是否可以在同一活动中同时运行两个网络视图?
我创建了一个简单的活动,其中包含两个并排的WebView。我使用以下代码来启动它们Android 在安卓系统中,是否可以在同一活动中同时运行两个网络视图?,android,android-webview,webchromeclient,Android,Android Webview,Webchromeclient,我创建了一个简单的活动,其中包含两个并排的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.setWebChromeCl
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>
我相信问题实际上是eclipse的问题,因为在完全删除webView1后,我收到了以下错误:
android.widget.TextView cannot be cast to android.webkit.WebView
你可以从我的代码中看到,考虑到你可以看到我在任何地方都没有这样做,实际上甚至还没有使用TextView,这是毫无意义的
一个完全干净和奇怪的问题仍然存在。我打算搬到安卓工作室
搬到安卓工作室,一切正常,处理布局的速度比我使用eclipse的经验快得多。
他们不是在一起的吗?您的屏幕有多大?不,它是nexus 7,它们并排排列,屏幕宽度大于1000dp。如果您不在webView1中加载url会发生什么情况?您的两个WebViews位于哪种类型的视图组中?没有变化,我开始怀疑这是否只是eclipse和我的xml文件的问题。