Pergunta

Eu tenho quatro botões dispostos em um tablelayout 2x2. Esses botões têm uma imagem à esquerda e algum texto. Os botões são excelentes no emulador por 1,5 e para 2,2, mas ao testar com 1.6 os dois botões na coluna RightThand são cortados para que eles faltem sua borda direta (o preenchimento à direita do texto está ausente e o botão termina abruptamente com os cantos quadrados em vez de arredondados). Há muito espaço para o tablelayout expandir para acomodar toda a largura dos botões. Isso acontece para todos os tamanhos de tela.

O layout se parece com isso e ele próprio aparece dentro de um relativeyout:

<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>

Os botões são estilizados da seguinte forma:

<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>

Suponho que este seja um bug específico de 1.6. Alguém mais se deparou com esse problema? Alguma sugestão de trabalho?

EDITAR: Tive a oportunidade de experimentá -lo com o Android 2.1 (tanto no emulador quanto no dispositivo), e o problema acontece lá também. Então 1,5 bom, 1,6 ruim, 2,1 ruim, 2,2 bom.

Foi útil?

Solução

Também encontrei o mesmo problema em 1.6 e 2.1, mas não em 1,5 nem 2.2.

eu uso LineraLayout e defina seu peso e pule o problema usando 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>

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top