【问题标题】:Android layout issue with buttons below WebViewWebView下方按钮的Android布局问题
【发布时间】:2010-12-13 06:42:30
【问题描述】:

所以我有一个 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>

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    您需要为 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>
    

    【讨论】:

    • 你先生,是我最喜欢的新人。即使经过几个月的 Android 开发,我仍在学习其中的一些基本知识。你有我的感激之情!
    • 修复前向引用问题的是 1.6:android-developers.blogspot.com/2009/10/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多