Keeping a Button under WebView in Android
I have trouble displaying(and most importantly - keeping) a Button under WebView, so it will stay there and not get eaten up by WebView after a call of loadUrl(). I can see开发者_如何学Python the Button in the right place when the emulator starts up, but when the page loads, the WebView always occupies the whole screen. Android SDK is 1.5.
Here is the layout:
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:text="Ok"
android:id="@+id/btnOk"
android:layout_width="120px"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<WebView android:id="@+id/webview1"
android:layout_above="@+id/btnOk"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
Set android:layout_weight="1"
on your WebView element and enclose it in a LinearLayout:
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<WebView android:id="@+id/webview1"
android:layout_above="@+id/btnOk"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<Button android:text="Ok"
android:id="@+id/btnOk"
android:layout_width="120px"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"/>
</LinearLayout>
精彩评论