2

i want to have 2 Relative Layouts on my screen. One below another. I made this code but it doesn't work. In this case i can see only upper Relative Layout insted of both and this layout take whole space although i set wrap_content.

EDIT!: I put below the second code which fails too.

EDIT 2!: I found problem... That's a bit... sad. Problem lie in my theme. I set background to png file which was too big and when i applied default theme via manifest then this happend. When i removed it all is good.

This version fails too.

New code:

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

    <RelativeLayout 
        android:id="@+id/some_id" 
        android:layout_above="@+id/some_id2"
        android:layout_alignParentTop="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button 
            android:id="@+id/main_button_localize" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="@string/main_localize" />

    </RelativeLayout>

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

        <ToggleButton 
            android:id="@+id/main_help" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"  />

    </RelativeLayout>

</RelativeLayout>

Old code:

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

    <RelativeLayout
        android:id="@+id/maps_manager_menu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" >

        <!-- Top -->
        <Button 
            android:id="@+id/maps_manager_top_left" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:contentDescription="@string/empty" />

        <Button 
            android:id="@+id/maps_manager_top_middle" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/maps_manager_top_left"
            android:contentDescription="@string/empty" />

        <Button 
            android:id="@+id/maps_manager_top_right" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/maps_manager_top_middle"
            android:contentDescription="@string/empty" />

        <!-- Middle -->
        <Button 
            android:id="@+id/maps_manager_middle_left" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/maps_manager_top_left"
            android:contentDescription="@string/empty" />

        <Button 
            android:id="@+id/maps_manager_middle_middle" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/maps_manager_middle_left"
            android:layout_below="@id/maps_manager_top_middle"
            android:contentDescription="@string/empty" />

        <Button 
            android:id="@+id/maps_manager_middle_right" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/maps_manager_middle_middle"
            android:layout_below="@id/maps_manager_top_right"
            android:contentDescription="@string/empty" />

        <!-- Bottom -->
        <Button 
            android:id="@+id/maps_manager_bottom_left" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/maps_manager_middle_left"
            android:contentDescription="@string/empty" />

        <Button 
            android:id="@+id/maps_manager_bottom_middle" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/maps_manager_bottom_left"
            android:layout_below="@id/maps_manager_middle_middle"
            android:contentDescription="@string/empty" />

        <Button 
            android:id="@+id/maps_manager_bottom_right" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/maps_manager_bottom_middle"
            android:layout_below="@id/maps_manager_middle_right"
            android:contentDescription="@string/empty" />

    </RelativeLayout>

    <RelativeLayout
           android:id="@+id/maps_manager_controls"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignBottom="true"
            android:layout_below="@id/maps_manager_menu" >

            <ToggleButton 
                android:id="@+id/maps_manager_help" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </RelativeLayout>

</RelativeLayout> 
Michal W
  • 793
  • 8
  • 24

4 Answers4

1

Better you take LinearLayout with vertical orientation as Parent for two child RelativeLayouts. If you can put 80:20 height weights for the RelativeLayouts then it would fit to the entire screen.

TNR
  • 5,839
  • 3
  • 33
  • 62
1
<ScrollView 
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">

<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" >
             <RelativeLayout
            android:id="@+id/maps_manager_menu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentTop="true" >

            <!-- Top -->
            <Button 
                android:id="@+id/maps_manager_top_left" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:contentDescription="@string/empty" />

            <Button 
                android:id="@+id/maps_manager_top_middle" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_top_left"
                android:contentDescription="@string/empty" />

            <Button 
                android:id="@+id/maps_manager_top_right" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_top_middle"
                android:contentDescription="@string/empty" />

            <!-- Middle -->
            <Button 
                android:id="@+id/maps_manager_middle_left" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/maps_manager_top_left"
                android:contentDescription="@string/empty" />

            <Button 
                android:id="@+id/maps_manager_middle_middle" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_middle_left"
                android:layout_below="@id/maps_manager_top_middle"
                android:contentDescription="@string/empty" />

            <Button 
                android:id="@+id/maps_manager_middle_right" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_middle_middle"
                android:layout_below="@id/maps_manager_top_right"
                android:contentDescription="@string/empty" />

            <!-- Bottom -->
            <Button 
                android:id="@+id/maps_manager_bottom_left" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/maps_manager_middle_left"
                android:contentDescription="@string/empty" />

            <Button 
                android:id="@+id/maps_manager_bottom_middle" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_bottom_left"
                android:layout_below="@id/maps_manager_middle_middle"
                android:contentDescription="@string/empty" />

            <Button 
                android:id="@+id/maps_manager_bottom_right" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_bottom_middle"
                android:layout_below="@id/maps_manager_middle_right"
                android:contentDescription="@string/empty" />

        </RelativeLayout>

        <RelativeLayout
               android:id="@+id/maps_manager_controls"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBottom="true"
                android:layout_below="@id/maps_manager_menu" >

                <ToggleButton 
                    android:id="@+id/maps_manager_help" 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </RelativeLayout>
    </RelativeLayout>
 </ScrollView>
1
<ScrollView 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" >

 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <RelativeLayout
            android:id="@+id/maps_manager_menu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentTop="true" >

            <!-- Top -->
            <Button 
                android:id="@+id/maps_manager_top_left" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:contentDescription="@string/hello_world" />

            <Button 
                android:id="@+id/maps_manager_top_middle" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_top_left"
                android:contentDescription="@string/hello_world" />

            <Button 
                android:id="@+id/maps_manager_top_right" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_top_middle"
                android:contentDescription="@string/hello_world" />

            <!-- Middle -->
            <Button 
                android:id="@+id/maps_manager_middle_left" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/maps_manager_top_left"
                android:contentDescription="@string/hello_world" />

            <Button 
                android:id="@+id/maps_manager_middle_middle" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_middle_left"
                android:layout_below="@id/maps_manager_top_middle"
                android:contentDescription="@string/hello_world" />

            <Button 
                android:id="@+id/maps_manager_middle_right" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_middle_middle"
                android:layout_below="@id/maps_manager_top_right"
                android:contentDescription="@string/hello_world" />

            <!-- Bottom -->
            <Button 
                android:id="@+id/maps_manager_bottom_left" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/maps_manager_middle_left"
                android:contentDescription="@string/hello_world" />

            <Button 
                android:id="@+id/maps_manager_bottom_middle" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_bottom_left"
                android:layout_below="@id/maps_manager_middle_middle"
                android:contentDescription="@string/hello_world" />

            <Button 
                android:id="@+id/maps_manager_bottom_right" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/maps_manager_bottom_middle"
                android:layout_below="@id/maps_manager_middle_right"
                android:contentDescription="@string/hello_world" />

        </RelativeLayout>

        <RelativeLayout
               android:id="@+id/maps_manager_controls"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/maps_manager_menu" >

                <ToggleButton 
                    android:id="@+id/maps_manager_help" 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </RelativeLayout>
    </RelativeLayout>
</ScrollView>
Nguyen Kien
  • 1,897
  • 2
  • 16
  • 22
0


Follow the following steps:

  1. Add ID to topmost relative layout say: android:id="@+id/rtvlt_first"
  2. In second RelativeLayout remove alignparenttop property.
  3. Add android:tobottomof="@id/rtvlt_first"...

    Try this....
    Good Luck!
Pratik
  • 831
  • 2
  • 8
  • 13