Question

I'm using a horizontal LinearLayout to divide a rectangular block of the device's screen into 3 equal parts. This is accomplished using weights.

The purpose of this is putting 3 buttons side by side, a settings button, a help button, and a contact button. As per my knowledge, it should follow that the first button in the LinearLayout is on the left, the next is in the middle, and the last is on the right, due to the hierarchy rules of a LinearLayout.

This is what the Visual Editor also shows. But when I run the application (and I've tried on multiple devices), the contact button ends up on the left, the settings button ends up in the middle, and the help button ends up on the right.

I tried changing the hierarchical structure of the code (i.e. I placed the code for contact button above the code for settings button, etc.) but it didn't make any difference to the result.

The code for the LinearLayout is below:

<LinearLayout
    android:id="@+id/icons"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="100">

    <ImageButton
        android:id="@+id/settings"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="33"
        android:src="@drawable/settings" />

    <ImageButton
        android:id="@+id/help"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="33"
        android:src="@drawable/help" />

    <ImageButton
        android:id="@+id/contact"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="33"
        android:src="@drawable/contact" />

</LinearLayout>
Was it helpful?

Solution

There is nothing wrong in the XML. If the application is really using the above XML, then changing the ordering of the ImageButtons in the layout should indeed change the ordering on the screen.

Here's 2 things that come to mind:

  1. There is a problem with your build/run process, and updated code changes are not reflect when you run your application. I suggest making a change to some obvious string resource and test if this is the problem. You should also do a clean build just in case.
  2. You have multiple layout files with the same name (for example, one in layout/ and the other in layout-land/), and you're not changing the right one.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top