1

I have created two webviews and need to put them under each other but it overlaps each other instead of going under each other. Which means that only the second screen webview is being displayed and not both.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <WebView
        android:id="@+id/webview2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:autoLink="web"
        android:scrollbars="none"
        android:textColor="@android:color/black" />


    <WebView
        android:id="@+id/webview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:autoLink="web"
        android:scrollbars="none"
        android:textColor="@android:color/black" />

</LinearLayout>

</ScrollView>

MainActivity.java

public class MainActivity extends Activity {

    WebView webView, webview2;
    CheckBox cbk1, cbk2;

    @SuppressLint("JavascriptInterface")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            webView = (WebView) findViewById(R.id.webview2);
            webview2 = (WebView) findViewById(R.id.webview1);
            webView.loadUrl("file:///android_asset/nextscreen.html");
            webview2.loadUrl("file:///android_asset/newscreen2.html");
    }
}
Janvi Vyas
  • 732
  • 5
  • 16
AnonymousZA
  • 121
  • 1
  • 11

3 Answers3

2

You are using FrameLayout which stacks views on top of other. Use LinearLayout instead.

Saurabh Thorat
  • 18,131
  • 5
  • 53
  • 70
1

Just put it in a LinearLayout:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  orientation="vertical">

  <WebView
  android:id="@+id/webview2"
  android:layout_width="match_parent"
  android:layout_height="50dp"
  android:autoLink="web"
  android:scrollbars="none"
  android:textColor="@android:color/black" />


  <WebView
  android:id="@+id/webview1"
  android:layout_width="match_parent"
  android:layout_height="570dp"
  android:autoLink="web"
  android:scrollbars="none"
  android:textColor="@android:color/black" />

</LinearLayout>
HedeH
  • 2,869
  • 16
  • 25
  • How can I change it a `scrollview`? So i can go up and down the whole screen? Would I have to just change `LinerLayout` to `ScrollView` – AnonymousZA Apr 29 '18 at 11:27
  • You'll need to wrap the `LinearLayout` with a `ScrollView` element. But this way you will probably have collision with the `WebView` touches, unless you make the `WebView` not touchable... – HedeH Apr 29 '18 at 11:35
  • What do you mean by none touchable? Do not understand. – AnonymousZA Apr 29 '18 at 11:37
  • Like this: https://stackoverflow.com/questions/3853794/disable-webview-touch-events-in-android. but first check if it works without it... – HedeH Apr 29 '18 at 11:38
0

because you are using FrameLayout as root . replace FrameLayout to LinearLayoutand add android:orientation="vertical"

Try this :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
 android:orientation="vertical"
>

<WebView
    android:id="@+id/webview2"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:autoLink="web"
    android:scrollbars="none"
    android:textColor="@android:color/black" />


<WebView
    android:id="@+id/webview1"
    android:layout_width="match_parent"
    android:layout_height="570dp"
    android:autoLink="web"
    android:scrollbars="none"
    android:textColor="@android:color/black" />

</LinearLayout >
SAYE
  • 1,247
  • 2
  • 20
  • 47