Android的布局问题,下面的WebView按钮 [英] Android layout issue with buttons below WebView

查看:262
本文介绍了Android的布局问题,下面的WebView按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个web视图我想显示为一个对话框。我想web视图以填满整个屏幕,除了它下面的一个按钮,我想留在对话框的底部,无论有多少内容是在web视图。目前我的WebView填补了对话框刚好按下按钮关闭屏幕。我敢肯定,这是一件pretty的容易,但对我的生活,我一直没能找到的布局,可欣赏到神奇的组合和属性值让它发挥好。只是要清楚,我已经得到了这么按钮浮在web视图,但我想要的WebView停在按钮上方滚动,如果是有道理的。

 < RelativeLayout的机器人:ID =@ + ID / RelativeLayout01
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =FILL_PARENT
                的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
  <的WebView机器人:ID =@ + ID / web视图
           机器人:layout_width =FILL_PARENT
           机器人:layout_height =WRAP_CONTENT
           />
  <按钮的android:文本=确定
          机器人:ID =@ + ID / btnOk
          机器人:layout_width =120px
          机器人:layout_height =WRAP_CONTENT
          机器人:layout_gravity =center_horizo​​ntal
          机器人:layout_alignParentBottom =真
          />
< / RelativeLayout的>
 

解决方案

您将要使用的android:layout_above =@ + ID / btnOk为你的web视图,并做FILL_PARENT宽度和web视图高度

不过,要注意,在1.5及以下,RelativeLayout的意见需要在命令中指明在XML中进行,换句话说正确..认可是非常重要的,你必须先有你的按钮,那么web视图,因为web视图将引用的按钮。我想,这在1.6或2.0改变了,但我不积极它。

 < RelativeLayout的机器人:ID =@ + ID / RelativeLayout01
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =FILL_PARENT
                的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

  <按钮的android:文本=确定
          机器人:ID =@ + ID / btnOk
          机器人:layout_width =120px
          机器人:layout_height =WRAP_CONTENT
          机器人:layout_gravity =center_horizo​​ntal
          机器人:layout_alignParentBottom =真
          机器人:layout_centerHorizo​​ntal =真/>
    <的WebView机器人:ID =@ + ID / web视图
           机器人:layout_above =@ + ID / btnOk
           机器人:layout_width =FILL_PARENT
           机器人:layout_height =FILL_PARENT
           />
< / RelativeLayout的>
 

So I have a webview I'd like to display as a dialog. I'd like the webview to fill the entire screen, except for a button below it that I'd like to stay at the bottom of the dialog regardless of how much content is in the webview. Currently my webview fills up the dialog just enough to push the button off the screen. I'm sure this is something pretty easy but for the life of me, I haven't been able to find the magical combination of layouts, views and attribute values to get it to play nice. Just to be clear, I've gotten it so the button floats over the webview but I'd like the webview to stop just above the button and scroll, if that makes sense.

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

解决方案

You will want to use android:layout_above="@+id/btnOk" for your webview, and do fill_parent for width and height of the webview.

However, it is important to note, that in 1.5 and below, RelativeLayout views need to be specified in order in your xml to be recognized correctly.. in other words, you have to have your Button first, then the WebView, since the WebView will reference the button. I think this has been changed in 1.6 or 2.0, but I am not positive which.

<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的布局问题,下面的WebView按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆