Question

I have a simple WebView in my layout, with the following setup

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rootView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/baserepeat"
    android:gravity="top|center_horizontal"
    android:orientation="vertical"
    android:paddingBottom="20dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp" >
 <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/productDetailContentWebview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="@drawable/baserepeat" />
//other items...

Inside my manifest I have the containing activity set to

    <activity
        android:name=".Products.ProductDetailActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="sensor"
        android:theme="@style/Theme.CPS" >
    </activity>

My Webview is populated with a simple HTML file on the device, which works nicely. The problem is that when I rotate the device from portrait to landscale, the webview becomes a good deal taller, pushing whatever was below it further down in my layout. The amount of content doesn't change - it is all set in OnCreate().

I'm using the Webview to render the content with it's own special stylesheet, and it must stay within the ScrollView.

I can provide more information if required :)

Était-ce utile?

La solution

I had the similar issue when working on 2.3/4.0...

I tried several things but the solution which helped me in getting rid of the core issue was:

removing screenSize from android:configChanges in AndroidManifest.xml

Hope it helps !!!

Autres conseils

Try including your webview inside a FrameLayout.

<LinearLayout>
   <FrameLayout>  
   <WebView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/productDetailContentWebview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:background="@drawable/baserepeat" />
   </FrameLayout>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top