Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android RelativeLayout: how to put a view below another view when both aren't at the same container

I had a TitleBar(#lotTopTitleBar) in the LinearLayout, and the LinearLayout will be full size of the screen, now, I want show a View(#lotFloatView) reference the TitleBar below, but both view aren't at the same level container, so the layout_below doesn't work, if anybody know about that, please help me a change.

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

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

        <LinearLayout android:id="@+id/lotTopTitleBar"
                      android:layout_width="match_parent"
                      android:layout_height="50dp">
        </LinearLayout>

        <LinearLayout android:layout_width="match_parent"
                      android:layout_height="0dp"
                      android:layout_weight="1">
        </LinearLayout>

        <LinearLayout android:layout_width="match_parent"
                      android:layout_height="50dp">
        </LinearLayout>

    </LinearLayout>

    <LinearLayout android:id="@+id/lotFloatView"
                  android:layout_width="120dp"
                  android:layout_height="wrap_content"
                  android:layout_below="@id/lotTopTitleBar">
        <Button android:layout_width="match_parent"
                android:layout_height="60dp"
                android:background="@null" />
        <Button android:layout_width="match_parent"
                android:layout_height="60dp"
                android:background="@null" />
    </LinearLayout>

</RelativeLayout>
like image 310
VinceStyling Avatar asked Jul 15 '13 03:07

VinceStyling


People also ask

What is relative layout in Android?

RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on.

How to place two views relative to each other in Android?

Following attributes can be used for doing so. Suppose there is one view in the center and its id is given as android:id="@+id/main" Therefore, the other new views can be placed relative to this view as following: This tells the new view that you have to be on the left side of the view whose id is main.

How to set textview below another textview in relativelayout in Android?

To set an element like TextView below another TextView in RelativeLayout in android app is easy to do with layout xml. You can do it like this. in the above code welcome TextView will come after heading. Now we will do it programatically.

How to position new views relative to existing views in relativelayout?

In a RelativeLayout you can keep (position) the new views relative to other existing views. Following attributes can be used for doing so. Suppose there is one view in the center and its id is given as android:id="@+id/main" Therefore, the other new views can be placed relative to this view as following:


Video Answer


1 Answers

I think you can achieve this by using relative layout instead of linear layout. I have not tested it but it should work.

    <RelativeLayout android:layout_width="match_parent"
              android:layout_height="match_parent"
              >

       <LinearLayout android:id="@+id/lotTopTitleBar"
                  android:layout_width="match_parent"
                  android:layout_height="50dp">
    </LinearLayout>
    <LinearLayout android:id="@+id/lotFloatView"
              android:layout_width="120dp"
              android:layout_height="wrap_content"
              android:layout_below="@id/lotTopTitleBar">
    <Button android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@null" />
    <Button android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@null" />
</LinearLayout>

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="0dp"
                  android:layout_below="@id/lotTopTitleBar"
                  android:id="@+id/lotLL"
                  android:layout_weight="1">
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent"
                  android:layout_below="@id/lotLL"
                  android:layout_height="50dp">
    </LinearLayout>

</RelativeLayout >

EDIT

    <LinearLayout android:layout_width="match_parent"
                  android:layout_below="@id/lotLL"
                  android:layout_alignParentBottom="true"
                  android:id="@+id/lotLastLL"
                  android:layout_height="50dp">
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_below="@id/lotTopTitleBar"
                  android:layout_above="@id/lotLastLL"
                  android:id="@+id/lotLL"
                  >
    </LinearLayout>
like image 86
Tarun Avatar answered Oct 16 '22 17:10

Tarun