将布局添加到屏幕底部

时间:2015-04-17 18:35:36

标签: android android-layout

我有以下XML布局。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip" >

    <TextView
        android:id="@+id/itemNumber"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="6dip"
        android:textSize="50px"/>

    <TextView
        android:id="@+id/secondLine"
        android:layout_width="fill_parent"
        android:layout_height="26dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/itemNumber"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/firstLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/secondLine"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:layout_toRightOf="@id/itemNumber"
        android:gravity="center_vertical"
        android:textSize="16sp" />

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

        <Button 
            android:text="Submit" 
            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>

我需要做的是编辑文字&amp;按钮显示在屏幕的底部。我使用3个文本视图显示为列表视图。所以我可以从列表中选择一个并将其输入到编辑文本中以提交值。

但我不能让它们出现在底部。我怎么能这样做?

3 个答案:

答案 0 :(得分:2)

替换

    android:layout_height="?android:attr/listPreferredItemHeight"

使用

    android:layout_height="match_parent"

//看看这个布局:

<?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"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="textView 1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="textView 2" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="textView 3" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="submit" />
    </LinearLayout>

</RelativeLayout>

答案 1 :(得分:1)

我有一个有效的例子..希望它会有所帮助

   <?xml version="1.0" encoding="utf-8"?>
    <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" >

     <!-- Header aligned to top -->

      <!-- Footer aligned to bottom -->
     <LinearLayout
       android:id="@+id/footer"
        android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:weightSum="1"
       android:gravity="center" >
       <Button
                android:id="@+id/button_show_contact"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Info." />

         </LinearLayout>

       <!-- Scrollable Content below header and above footer -->

      <ScrollView
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/footer" >

      <LinearLayout
        android:id="@+id/liimage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
     </LinearLayout>
     </ScrollView>   
</RelativeLayout>

如果您有任何问题,请打电话

答案 2 :(得分:0)

只需添加代码行:

android:gravity="bottom"

编辑:更容易将第二个布局更改为:LinearLayout