woshiwoxingfu 2012-09-14 02:27 采纳率: 100%
浏览 6680
已采纳

如何调整屏幕底部的视图?

这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView android:text="@string/welcome" 
        android:id="@+id/TextView" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">
    </TextView>

    <LinearLayout android:id="@+id/LinearLayout" 
        android:orientation="horizontal"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:gravity="bottom">

            <EditText android:id="@+id/EditText" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content">
            </EditText>

            <Button android:text="@string/label_submit_button" 
                android:id="@+id/Button" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content">
            </Button>

    </LinearLayout>

</LinearLayout>

它现在是左边这样,但是我想让他像右边这样的
enter image description here

比较容易的做法就是设置TextView充满整个高度,但是这会引起按钮没有空间或者是输入框。基本上这个问题是我想要submit button和text entry在底部是一个合适的高度,text view填满剩下的控件,同样的在这个水平线性布局里边,我想要submit button包含它的内容,text entry来包含剩下的空间。
如果在这个线性布局里的第一个项目是告知它就是用来填满这个布局的,没有给其他项目留空间,我在这个布局里如何得到一个首先是在这个线性布局里,填满除了最低要求的其他项目的项目?

编辑1:

Relative Layouts 确实是答案,谢谢。

   <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

    <TextView 
        android:text="@string/welcome" 
        android:id="@+id/TextView"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
    </TextView>

    <RelativeLayout 
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <Button 
            android:text="@string/label_submit_button" 
            android:id="@+id/Button"
            android:layout_alignParentRight="true" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </Button>

        <EditText 
            android:id="@+id/EditText" 
            android:layout_width="fill_parent"
            android:layout_toLeftOf="@id/Button"
            android:layout_height="wrap_content">
        </EditText>

    </RelativeLayout>

</RelativeLayout>
  • 写回答

4条回答

  • Sueyexin 2012-09-14 02:45
    关注

    我想你应该试试relative layout.
    如果你使用相对布局来填充整个屏幕,你应该可以使用android:layout_alignParentBottom 来移动按钮到屏幕的底部。
    如果你的屏幕底部的视图不是以相对布局来显示的,那么也许上边的布局将占据所有的空间。在这种情况下,在这个android布局:以上的布局中,在你的布局文件和剩下的布局位置,首先你应该把这个视图放在底部。这能够使按钮的视图占据尽可能多的像他需要的空间,剩下的布局可以填满剩下的所有屏幕。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站