After designing layouts in Android for a while now, I still cannot get the hang of it. Often the results are unpredictable.
I think part of this boils down to some layout options not working well together. I.e. if you are using one way of specifying your layout, you're not meant to use some other way.
Notably, for me, changing layout_width
from fill_parent
to wrap_content
usually changes the world. Let me give you another specific example:
Part of my activity's layout is a LinearLayout:
<LinearLayout android:id="@+id/ll2" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<LinearLayout android:id="@+id/ll2a" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1">
<TextView android:id="@+id/l_cover" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/book_item_l_cover">
</TextView>
<ImageButton android:id="@+id/i_cover"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scaleType="centerInside" android:gravity="center"
android:layout_weight="1" android:adjustViewBounds="true"
android:src="@drawable/spinner_black_76" android:minWidth="400dip">
</ImageButton>
</LinearLayout>
<LinearLayout android:id="@+id/ll2b" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1">
<TextView android:id="@+id/l_back_cover" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/book_item_l_back_cover">
</TextView>
<ImageButton android:id="@+id/i_back_cover"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scaleType="centerInside" android:gravity="center"
android:layout_weight="1" android:adjustViewBounds="true"
android:src="@drawable/spinner_black_76">
</ImageButton>
</LinearLayout>
</LinearLayout>
To get 2 columns of left-aligning label-button combinations next to eachother I had to use the layout_weight
attributes. The ImageButtons shrink around their images due to the adjustViewBounds
attributes. This gets me a pretty good result.
Now what I finally also wanted was to have buttons of a certain minimum size so a finger can always easily press them, even when they do not contain any image (and they will shrink to only a few millimeters). I experimented with setting android:minWidth="400dip"
as you can see. I expected the button to fill up the entire half of the screen in width (400 is quite a large value), but I'm not seeing any difference.
I guess one of the other attributes above is preventing minWidth
from having any impact. And I could probably go experiment and disable some others to see what it gives me. But my question here is: does anybody have any (logical) information on which attribute prevents or counter-intuitively influences whichother? I'd like to get this sorted once and for all. Is this documented somewhere?