如何排列的观点在屏幕的底部? [英] How to align views at the bottom of the screen?

查看:188
本文介绍了如何排列的观点在屏幕的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的布局code;

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>

    < TextView的Andr​​oid版本:文本=@字符串/欢迎
        机器人:ID =@ + ID / TextView的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>
    < / TextView的>

    <的LinearLayout机器人:ID =@ + ID / LinearLayout中
        机器人:方向=横向
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:重力=底和GT;

            < EditText上机器人:ID =@ + ID / EditText上
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT>
            < /的EditText>

            <按钮的android:文本=@字符串/ label_submit_button
                机器人:ID =@ + ID /按钮
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT>
            < /按钮>

    < / LinearLayout中>

< / LinearLayout中>
 

这是什么貌似是在左边,我希望它看起来就像是在正确的。

Android的布局

答案显然是设置的TextView为FILL_PARENT的高度,但这个会导致无房可留给按钮或输入字段。本质上,问题是,我想提交按钮和文本输入是在底部我想提交按钮来包装其内容的固定高度和文本视图水平线性布局,以填补空间的其余部分,同样和对于文本输入,以填补空间的其余部分。

如果在一个线性布局中的第一项被告知要FILL_PARENT它正是这么做的,不留下任何余地其他项目,我怎么是先在一个线性布局的项目,以填补所有的空间除了规定的最低这些项目在布局中休息吗?

编辑:

相对布局确实的答案 - 谢谢

 < XML版本=1.0编码=UTF-8&GT?;
    < RelativeLayout的
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>

    <的TextView
        机器人:文本=@字符串/欢迎
        机器人:ID =@ + ID / TextView的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentTop =真正的>
    < / TextView的>

    < RelativeLayout的
        机器人:ID =@ + ID / InnerRelativeLayout
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真正的>

        <按钮
            机器人:文本=@字符串/ label_submit_button
            机器人:ID =@ + ID /按钮
            机器人:layout_alignParentRight =真
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT>
        < /按钮>

        <的EditText
            机器人:ID =@ + ID / EditText上
            机器人:layout_width =FILL_PARENT
            机器人:layout_toLeftOf =@ ID /按钮
            机器人:layout_height =WRAP_CONTENT>
        < /的EditText>

    < / RelativeLayout的>

< / RelativeLayout的>
 

解决方案

我想你应该尝试的相对布局
如果你有一个填满整个屏幕相对的布局,你应该能够使用<一个href="http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html#attr_android%3alayout_alignParentBottom"><$c$c>android:layout_alignParentBottom移动的按钮,以在屏幕的底部。

如果你的意见在底部相对布局没有显示,那么也许它上面的布局需要的所有空间。在这种情况下,你可以把认为应该是在底部,首先在布局文件,上面的意见的布局静止位置的android:layout_above 。这使得底部的观点,因为它需要与布局的其余的可以填充屏幕的其余全部采取尽可能多的空间。

Here's my layout code;

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

What this looks like is on the left and what I want it to look like is on the right.

The obvious answer is to set the TextView to fill_parent on height but this causes no room to be left for the button or entry field. Essentially the issue is that I want the submit button and the text entry to be a fixed height at the bottom and the text view to fill the rest of the space, similarly in the horizontal Linear layout I want the submit button to wrap its content and for the text entry to fill the rest of the space.

If the first item in a Linear Layout is told to fill_parent it does exactly that, leaving no room for other items, how do I get an item which is first in a linear layout to fill all space apart from the minimum required by the rest of the items in the layout?

EDIT:

Relative Layouts were indeed the answer - Thank you!

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

解决方案

I think you should try a relative layout.
If you have a relative layout that fills the whole screen you should be able to use android:layout_alignParentBottom to move the button to the bottom of the screen.

If your views at the bottom are not shown in a relative layout then maybe the layout above it takes all the space. In this case you can put the view that should be at the bottom, first in your layout file and position the rest of the layout above the views with android:layout_above. This enable the bottom view to take as much space as it needs and the rest of the layout can fill all the rest of the screen.

这篇关于如何排列的观点在屏幕的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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