我在展示線性佈局中的WebView時遇到了問題。在我的代碼中,我可以將WebView視圖更改爲TextView,並且一切正常。我想顯示11個包含Google搜索結果的WebView面板。WebView未出現在LinearLayout上
我MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
...
LinearLayout relLay = (LinearLayout) findViewById(R.id.main_relLay);
LayoutInflater inflater = (LayoutInflater) getApplication()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(int i=1; i<11; i++){
View v_child = inflater.inflate(R.layout.row, null);
relLay.addView(v_child);
String link = "https://www.google.com/search?q=" + i;
WebView web_view = (WebView) v_child.findViewById(R.id.row_webView);
web_view.loadUrl(message);
}
...
我activity_main.xml中
<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" >
<ScrollView
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="450dp" >
<LinearLayout
android:id="@+id/main_relLay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0B7A3B"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
我row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/row_webView"
android:background="#323232"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="gone" >
</WebView>
</LinearLayout>
由於Android:知名度= 「水漲船高」 ...... – KOTIOS 2014-09-03 09:41:59
@DIVA感謝M8 – Volz 2014-09-03 09:45:17
@Volz看看我的答案。 – GrIsHu 2014-09-03 09:49:36