Question

I've got the following xml file:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:background="@android:color/transparent"
    android:layout_marginTop="0px"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:weightSum="1"
    android:orientation="horizontal">
      <Button android:id="@+id/info"   android:text="Info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom"></Button>
      <Button android:id="@+id/town"   android:text="Town" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom"></Button>
      <Button android:id="@+id/unit"   android:text="Unit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom"></Button>
      <Button android:layout_height="wrap_content" android:text="EndTurn" android:id="@+id/endturn" android:layout_width="wrap_content" android:layout_gravity="bottom"></Button>
  </LinearLayout>

which provides the following result: http://i42.tinypic.com/otdkb4.png

Now I've got some questions about this:

  1. The top and bottom padding, how to get rid of it? I tried RelativeLayout, multiple layouts within each other, padding, margin, changing height nothing seem to affect it in any way.

  2. Is there a way to get the layout transparent? android:background seems to be the wrong one.

  3. Between the third and the fifth button is a bit more space (where the fourth button should be). I catch it the in the program and set it to invisible.

    unitButton.setVisibility(INVISIBLE); unitButton.setWidth(0);

Now the space between the two buttons is more than double of the normal range (between 1 and 2) Any idea on this? - Altough this is a minor problem

Thanks in advance.

Was it helpful?

Solution

1: Is the layout presented in a Dialog? If so, that'll give you some headaches. To get more control you should either create your own custom Dialog extension (as some dialog layout values are hardcoded), or display your layout in another way (a new activity on top, or using a framelayout perhaps)?

2: To get a layout transparent, simply don't give it a background-attribute. (Though, if you really are using a dialog, the dialog box is not transparent, and it is that which you see. You can also set it to be transparent by setting background to "#00000000" (which is what you do).

3: A View with visibility as "invisible" is still measured, that means both its width/height as well as its margins and padding is displayed as empty space in your layout. Setting the visibility to "gone" instead will not measure it, and you won't need the setWidth(0) either. (You can still display it later by setting it back to "visible")

Edit: removing the unused "weightSum" attribute might also be a good idea, as the view is now expecting its children to have a total weight of something other than 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top