开发者

How to place Relative layout at bottom of screen(or linear layout).?

I have following in xml

I wanna put the second linear layout at the bottom of the screen. How will i do? I have set the property of second Relative layout to bottom but still not showing at bottom..

**

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andr开发者_StackOverflowoid="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>

** Thanx in advance


I was searching for this a while too. My just found solution is to use the property:

android:layout_alignParentBottom="true"

instead of your existing android:layout_gravity="bottom"

This unfortunately with my layout only works when having an additional RelativeLayout as root layout and the rest added to it. Maybe this is not always the case, but with having a LinearLayout (even when told to use fill_parent) it only used the height all added elements needed and put my footer at the bottom of those.

I came to this solution, looking at this related question: How do I achieve the following result using RelativeLayout?

EDIT here because format in answer comment got lost: Do you mean you can't re-write it or that it didn't work?

I had a vertical LinearLayout too and my new xml structure looks (without the layout size params etc.) sth. like this:

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


The Layout you want at the bottom should have:
android:gravity = "bottom"
and its parent should have:
android:layout_height="fill_parent"


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


You should put a View before your last layout with weight 1, and it will put it to bottom. Like this:

    <View android:id="@+id/emptySpace"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />


Try using:

<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


For my it's work.

    <RelativeLayout
    android:id="@+id/InnerRelativeLayout"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="#fff"
    android:gravity="bottom"
    app:layout_anchor="@+id/fab_inout"
    app:layout_anchorGravity="bottom|center">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="dsfsdfasdf df" />

</RelativeLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜