三个控件,button1,web,button2
<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"
    tools:context=".MainActivity" >    <Button 
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:text="Button1"/>
    
    <WebView 
        android:id="@+id/web"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/but1"/>
    
    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/web"
        android:text="Button2" /></RelativeLayout>
因为加载的网页太大,button2不能显示
如何能让button1在顶部显示,button2在底部显示,而无论网页大小如何,WebView都只且占据两个button中间的空间?Android布局

解决方案 »

  1.   


    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >    <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="Button" />    <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:text="Button" />    <WebView
            android:id="@+id/webView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/button2"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/button1" /></RelativeLayout>
    button1
    android:layout_alignParentTop="true"button2
    android:layout_alignParentBottom="true"webview
    android:layout_below="@+id/button1"
    android:layout_above="@+id/button2"
      

  2.   

    给button2的属性添加android:layout_alignParentBottom="true"
    让webView有属性android:layout_above="@id/button2"
      

  3.   

    为什么不用线性布局LinearLayout
    这样只需给WebView加一个layout_weight=1即可,它占据剩下的布局空间
      

  4.   

    用线性布局。。button设置高度为wrap。。webview的layoutweith为1  layoutheight为fill就可以了
      

  5.   

    可以改用线性布局,WebView设置layout_height:0dp,layout_weight:1