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

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办