代码之家  ›  专栏  ›  技术社区  ›  Sandy

如何在屏幕底部放置相对布局(或线性布局)。?

  •  8
  • Sandy  · 技术社区  · 14 年前

    我有以下xml格式的

    我想把第二个线性布局放在屏幕的底部。 我该怎么办? 我已将第二个相对布局的属性设置为底部,但仍然没有在底部显示。。

    **

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent">    
    <RelativeLayout android:id="@+id/RelativeLayout01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">   
    </RelativeLayout>
    <RelativeLayout android:id="@+id/RelativeLayout02" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">   
    </RelativeLayout>
    <RelativeLayout android:layout_height="wrap_content" 
        android:layout_width="fill_parent"
        android:layout_gravity="bottom">
    </RelativeLayout>
    </LinearLayout>
    

    **

    5 回复  |  直到 14 年前
        1
  •  11
  •   fredley    14 年前

    您想要在底部的布局应该有:
    android:gravity = "bottom"
    其父级应具有:
    android:layout_height="fill_parent"

        2
  •  16
  •   Community CDub    8 年前

    android:layout_alignParentBottom="true"
    

    而不是你现有的 android:layout_gravity="bottom"

    不幸的是,我的布局只有在有额外的 RelativeLayout 其他的都加进去了。也许情况并非总是这样,但有了 LinearLayout (即使被告知使用 fill_parent

    我找到了这个解决方案,看看这个相关的问题: How do I achieve the following result using RelativeLayout?

    你的意思是你不能重写它还是它不起作用?

    <RelativeLayout>
        <RelativeLayout 
            android:id="@+id/RelativeLayout01">
        </RelativeLayout>
        <RelativeLayout 
            android:id="@+id/RelativeLayout02" 
            android:layout_below="@+id/RelativeLayout01">   
        </RelativeLayout>
        <RelativeLayout 
            android:layout_below="@+id/RelativeLayout02" 
            android:layout_alignParentBottom="true">
        </RelativeLayout>
    </RelativeLayout>
    
        3
  •  1
  •   Teraiya Mayur    11 年前
    <Linearlayout android:layout_height="fill_parent" 
    android:orinationtation="vertical"
    android:layout_width="fill_parent">
    
    <RelativeLayout  android:layout_height="0dp" 
    android:layout_width="fill_parent"
    android:weight="1">
    </RelativeLayout>
    
    <RelativeLayout 
    android:layout_height="0dp" 
    android:layout_width="fill_parent"
    android:weight="1"
    >   
    </RelativeLayout>
    
    
    
    </Linearlayout >
    
        4
  •  1
  •   IDontEvenKnow    9 年前

    你应该在权重为1的最后一个布局之前放置一个视图,它将把它放在底部。这样地:

        <View android:id="@+id/emptySpace"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />
    
        5
  •  1
  •   Laurel Enrique    9 年前

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="#ffb3e5fc"
       android:id="@+id/linearLayout1">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom">
    <Button
        android:id="@+id/button1"
        android:text="Left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/centerPoint" />
    <TextView
        android:id="@+id/centerPoint"
        android:text=""
        android:layout_width="1dip"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" />
    <Button
        android:id="@+id/button2"
        android:text="Right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/centerPoint" />
    </RelativeLayout>
    </LinearLayout>
    

    It produces something that looks like this