Buttons in TableLayout cropped on Android 1.6 and 2.1 (but not on 1.5 or 2.2)
العربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
I have four buttons arranged in a 2x2 TableLayout. These buttons each have an image on the left and some text. The buttons display fine in the emulator for 1.5, and for 2.2, but when testing with 1.6 the two buttons in the righthand column are cropped so that they are missing their righthand edge (the padding to the right of the text is missing and the button ends abruptly with squared off corners rather than rounded ones). There is plenty of room for the TableLayout to expand to accommodate the full width of the buttons. This happens for all screen sizes.
The layout looks like this and itself appears within a RelativeLayout:
<TableLayout android:id="@+id/buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:paddingTop="10dp">
<TableRow>
<Button android:id="@+id/button1"
style="@style/LaunchButton"
android:drawableLeft="@drawable/button1"
android:text="@string/button1"/>
<Button android:id="@+id/button2"
style="@style/LaunchButton"
android:drawableLeft="@drawable/button2"
android:text="@string/button2"/>
</TableRow>
<TableRow>
<Button android:id="@+id/button3"
style="@style/LaunchButton"
android:drawableLeft="@drawable/button3"
android:text="@string/button3"/>
<Button android:id="@+id/button4"
style="@style/LaunchButton"
android:drawableLeft="@drawable/button4"
android:text="@string/button4"/>
</TableRow>
</TableLayout>
The buttons are styled as follows:
<style name="LaunchButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">fill_horizontal</item>
<item name="android:textSize">24dp</item>
<item name="android:textStyle">bold</item>
</style>
I'm assuming this is a 1.6-specific bug. Has anybody else come across this problem? Any suggestions for work-arounds?
EDIT: I've had the opportunity to try it with Android 2.1 (both on the emulator and a device), and the problem happens there too. So 1.5 good, 1.6 bad, 2.1 bad, 2.2 good.
Answer |
I also ran into the same problem on 1.6 and 2.1 but not on 1.5 nor 2.2.
I use LineraLayout and set its weight instead and skip the problem using TableLayout.
<LinearLayout
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent"
android:layout_weight="1" android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_weight="1" android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_weight="1" android:layout_height="wrap_content"
android:gravity="center">
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>