karlosos
karlosos

Reputation: 1174

WebView doesn't appear on LinearLayout

I have a problem with showing WebView in Linear layout. In my code I can change WebView view to TextView and everything work well. I want to show 11 WebView panels which contain Google search results.

My 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);
}
...

My 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>

My 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>

Upvotes: 2

Views: 895

Answers (2)

Programmer
Programmer

Reputation: 878

Modify your 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>

Upvotes: 0

GrIsHu
GrIsHu

Reputation: 23638

You have kept your WebView visibility GONE by default that is why its not showing.

Just remove the line android:visibility="gone" from your WebView in your xml file.

 <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>  

Upvotes: 1

Related Questions