在TableLayout裁剪按钮在Android 1.6和2.1(而不是在1.5或2.2)是在、而不、按钮、Android

2023-09-07 00:53:49 作者:孤病i

我有四个按钮安排在一个2x2 TableLayout。这些按钮具有在左侧和一些文本的图像。按钮显示效果细腻,在仿真器1.5和2.2,但1.6测试时,在右侧栏中的两个按钮被裁剪,使他们缺少自己的右手边(填充到文本的权利缺失和按钮与方形的角落,而不是四舍五入的)突然结束。有足够的空间用于TableLayout扩大以容纳按键的全宽。这种情况对于所有的屏幕尺寸。

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.

布局看起来像这一点,本身会出现一个RelativeLayout的范围内:

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>

我假设这是一个1.6的特定错误。有其他人遇到过这个问题吗?对于变通有什么建议?

I'm assuming this is a 1.6-specific bug. Has anybody else come across this problem? Any suggestions for work-arounds?

编辑:我有机会与Android 2.1(无论是在模拟器和设备)试一试,并发生了问题也有。所以1.5好,1.6坏的,坏的2.1,2.2不错的。

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.

推荐答案

我也遇到了同样的问题,在1.6和2.1,但不是1.5,也不2.2。

I also ran into the same problem on 1.6 and 2.1 but not on 1.5 nor 2.2.

我用 LineraLayout 并设置它的重量,而不是使用跳过问题 TableLayout

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>