Romain
Romain

Reputation: 87

Android: problem scrolling my activity including a WebView

I included a WebView in my activity and load some Javascript in it which is then going to get data from an external website. This works and displays fine but the problem is that my activity doesn't scroll when the WebView is done loading so I can't see the bottom of the WebView such as all the other Views I put below this. Any idea of how I should handle this? Cheers.

Upvotes: 0

Views: 2332

Answers (2)

CommonsWare
CommonsWare

Reputation: 1007543

This works and displays fine but the problem is that my activity doesn't scroll when the WebView is done loading so I can't see the bottom of the WebView such as all the other Views I put below this.

You need to change your layout such that the "other Views I put below this" will be on the screen, and the WebView simply takes up the remaining space.

For example, here is a layout showing a WebView with a Button:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <WebView android:id="@+id/webkit"
            android:layout_width="fill_parent" 
        android:layout_height="0px"
        android:layout_weight="1"
    />
    <Button android:id="@+id/helpcast"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="View Helpcast"
    />
</LinearLayout>

Because the WebView is set up with a 0px height but a weight of 1, and because the Button specifies no weight, the WebView will fill all space left over after the Button is on-screen. The WebView content will scroll inside the WebView itself, if needed, based upon whatever Web page you load in there.

Upvotes: 0

prolink007
prolink007

Reputation: 34584

Are you using scrollview in your layout? Try that and see if that helps.

Here is a link to the developer page

Upvotes: 1

Related Questions