Android布局问题与WebView下面的按钮

Mat*_*ttC 4 android android-layout

所以我有一个webview我想显示为对话框.我希望webview能够填满整个屏幕,除了下面的按钮,我想留在对话框的底部,无论webview中有多少内容.目前,我的webview填满了对话框,足以将按钮从屏幕上移开.我确信这很容易,但对于我的生活,我无法找到布局,视图和属性值的神奇组合,以使其发挥得很好.为了清楚起见,我已经得到它,因此按钮浮动在webview上,但我希望webview停在按钮上方并滚动,如果这是有道理的.

<RelativeLayout android:id="@+id/RelativeLayout01" 
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android">
  <WebView android:id="@+id/webview"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           /> 
  <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"
          />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Tim*_*m H 8

您将需要为webview使用android:layout_above ="@ + id/btnOk",并为webview的宽度和高度执行fill_parent.

但是,需要注意的是,在1.5及以下版本中,需要按顺序指定RelativeLayout视图才能正确识别xml ..换句话说,你必须首先使用Button,然后是WebView,因为WebView将参考按钮.我认为这已经在1.6或2.0中有所改变,但我并不乐观.

<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/webview"
           android:layout_above="@+id/btnOk"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           /> 
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)