Forum Xamarin.Android

Problem with nested axml layout

Hello,

I want to layout a quite simple thing in axml and i don't know where is my mistake.

I want to have a title bar at the top of the screen and two containers of equal size filling up the screen.
Now the upper first container should contain one line of buttons on the top and a second line of buttons on the bottom of the first half container. The rest in between the upper line of buttons and the lower line of buttons should be filled up with a container (which later should contain a listview).

This is what I think it should look like ...

<?xml version="1.0" encoding="utf-8"?>










I nearly tried everything without success.
Where is my mistake ?

Thanks in advance

Christian Gill

Posts

  • ChristianGillChristianGill DEMember ✭✭

    Opps sorry the amxl got lost. Now i try to attache it.

  • CheesebaronCheesebaron DKInsider, University mod

    Paste your AXML here, mark it and press the "C" icon in the editor. I don't like to download and extract archive files from unknown sources...

  • ChristianGillChristianGill DEMember ✭✭

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/asknumber_layout_root" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minWidth="25px" android:minHeight="25px" android:isScrollContainer="false"> <fragment class="OrderClient.TitleBarFragment" android:id="@+id/order_titlebar_fragment" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:orientation="vertical" android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:id="@+id/order_upper_area" android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="top" android:layout_weight="1" android:clipChildren="true" android:clipToPadding="true"> <RelativeLayout android:id="@+id/order_button_line_1" android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:layout_gravity="top" android:layout_width="match_parent" android:layout_height="wrap_content" /> <RelativeLayout android:id="@+id/order_list_area" android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:layout_below="@+id/order_button_line_1" android:layout_above="@+id/order_button_line_2" android:layout_width="match_parent" android:layout_height="wrap_content" /> <RelativeLayout android:id="@+id/order_button_line_2" android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:layout_gravity="bottom" android:layout_width="match_parent" android:layout_height="wrap_content" /> </RelativeLayout> <RelativeLayout android:id="@+id/order_lower_area" android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="bottom" android:layout_weight="1" /> </LinearLayout> </LinearLayout>

  • CheesebaronCheesebaron DKInsider, University mod

    It is bad practice to nest layout as much as you do. Please nest layouts as little as possible.

    Something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:id="@+id/asknumber_layout_root"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:isScrollContainer="false">
        <fragment
            class="OrderClient.TitleBarFragment"
            android:id="@+id/order_titlebar_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <LinearLayout
            android:orientation="horizontal"
            android:id="@+id/order_button_line_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="1" />
            <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="2" />
            <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="3" />
        </LinearLayout>
        <ListView
            android:id="@+id/order_list_area"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp" />
        <LinearLayout
            android:id="@+id/order_button_line_2"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="1" />
            <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="2" />
            <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="3" />
        </LinearLayout>
        <RelativeLayout
            android:id="@+id/order_lower_area"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
    

    Produces:
    screenshot

    Which I translated your text description to.

  • ChristianGillChristianGill DEMember ✭✭

    Hello.

    Thanks a lot for your efforts.
    I guess the problem is that there is really a bug in the axml if you nest the layout more than a few levels. (Please correct me if I'm wrong.)
    Now I have build the gui in another way.
    I've divided the layout in 3 seperate axml files (using fragments)
    So the main axml (for the Activity) contains the title bar and the two relative layouts dividing the rest of the screen in two seperated areas.
    Then i have created two additional axml. One layout for the content of the upper window and another one for content of the lower window.
    The combination works as expected.

Sign In or Register to comment.