【问题标题】:Buttons in TableLayout cropped on Android 1.6 and 2.1 (but not on 1.5 or 2.2)TableLayout 中的按钮在 Android 1.6 和 2.1 上被裁剪(但不是在 1.5 或 2.2 上)
【发布时间】:2023-03-10 03:00:01
【问题描述】:

我有四个按钮排列在一个 2x2 的表格布局中。这些按钮在左侧都有一个图像和一些文本。这些按钮在 1.5 和 2.2 的模拟器中显示良好,但是在使用 1.6 进行测试时,右侧列中的两个按钮被裁剪,因此它们缺少右侧边缘(文本右侧的填充缺失并且按钮突然以方形角而不是圆形角结束)。 TableLayout 有足够的空间来扩展以适应按钮的整个宽度。这适用于所有屏幕尺寸。

布局看起来像这样,它本身出现在一个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>

按钮的样式如下:

<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 特定的错误。有没有其他人遇到过这个问题?有什么解决方法的建议吗?

编辑:我有机会在 Android 2.1 上试用它(在模拟器和设备上),问题也发生在那里。所以1.5好,1.6坏,2.1坏,2.2好。

【问题讨论】:

  • 目前最简单的解决方法是指定一个固定的按钮宽度,而不是将其设置为“wrap_content”并让布局自行解决。

标签: android tablelayout


【解决方案1】:

我在 1.6 和 2.1 上也遇到了同样的问题,但在 1.5 和 2.2 上都没有。

我使用LineraLayout 并设置它的权重并使用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>

【讨论】:

    猜你喜欢
    • 2011-06-09
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多