2014-09-03 68 views
2

我在展示线性布局中的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> 
+0

由于Android:知名度= “水涨船高” ...... – KOTIOS 2014-09-03 09:41:59

+0

@DIVA感谢M8 – Volz 2014-09-03 09:45:17

+0

@Volz看看我的答案。 – GrIsHu 2014-09-03 09:49:36

回答

0

你使你的WebView知名度默认是GONE为什么它没有显示。

只需从您的xml文件中的WebView中删除行android:visibility="gone"即可。

<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" 
     > //Remove visibility line. 
    </WebView> 
0

修改您的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" 
> 
     </WebView> 
</LinearLayout>