0

This is my code. I'm unable to align webview exactly below the linear layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="50dip"
    />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/etenterurl"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1.0"
        android:inputType="textUri" />

    <Button
        android:id="@+id/buttongo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3.0"
        android:text="Go" />
</LinearLayout>

</FrameLayout>
Anirudh
  • 2,767
  • 5
  • 69
  • 119

2 Answers2

3

There is a bug in the WebView implementation and padding does not work properly,

See: How to add padding around a WebView for a workaround

But i think this is what your are looking for:

A RelativeLayout solves this problem with ease! Take a close look at the layout_below argument given to the WebView

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

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/bar" />

    <LinearLayout
        android:id="@+id/bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/etenterurl"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1.0"
            android:inputType="textUri" />

        <Button
            android:id="@+id/buttongo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3.0"
            android:text="Go" />
    </LinearLayout>

</RelativeLayout>
Community
  • 1
  • 1
Rolf ツ
  • 8,611
  • 6
  • 47
  • 72
1

Why not change your FrameLayout to a RelativeLayout and then use

<LinearLayout
    android:id="@+id/bar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    ...

</LinearLayout>

<WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/bar"
    android:layout_below="@id/bar" />
Mike T
  • 4,747
  • 4
  • 32
  • 52