Выровнять по центру таблицу + кнопки - PullRequest
0 голосов
/ 17 июня 2011

Я хочу, чтобы это работало на экранах всех размеров, поэтому я не думаю, что использование отступов - лучший способ решить эту проблему. Я могу центрировать все, когда оно в вертикальном положении, но когда оно горизонтальное, кажется, что ничего не выравнивается ...

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:orientation = "horizontal"
android:layout_gravity = "center">

<TableLayout
    android:layout_height = "wrap_content"
    android:layout_width="wrap_content"
    android:gravity = "center" 
    android:layout_gravity="center_horizontal">
    <TableRow 
    android:id="@+id/tableRow1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
        <TextView 
        android:textSize="24.5sp" 
        android:id="@+id/textView1" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:layout_marginBottom="20dip" 
        android:text="Bubb" 
        android:layout_width="wrap_content">
        </TextView>
    </TableRow>
    <TableRow android:baselineAligned="false">
        <Button
        android:id = "@+id/continue_button"
        android:background="@drawable/and_button" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft = "@dimen/pad_horizontal"
        android:paddingRight = "@dimen/pad_horizontal"
        android:paddingTop = "@dimen/pad_vertical"
        android:paddingBottom = "@dimen/pad_vertical"
        android:text = "@string/first_label" 
        android:layout_margin="@dimen/margin"/>
    </TableRow>
    <TableRow>
        <Button
        android:id = "@+id/new_button"
        android:text = "@string/second_label" 
        android:background="@drawable/and_button" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft = "@dimen/pad_horizontal"
        android:paddingRight = "@dimen/pad_horizontal"
        android:paddingTop = "@dimen/pad_vertical"
        android:paddingBottom = "@dimen/pad_vertical"
        android:layout_margin="@dimen/margin"/>
    </TableRow>
    <TableRow>
        <Button
        android:id = "@+id/about_button"
        android:text = "@string/third_label" 
        android:background="@drawable/and_button" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft = "@dimen/pad_horizontal"
        android:paddingRight = "@dimen/pad_horizontal"
        android:paddingTop = "@dimen/pad_vertical"
        android:paddingBottom = "@dimen/pad_vertical"
        android:layout_margin="@dimen/margin"/>
    </TableRow>
    <TableRow>
        <Button
        android:id = "@+id/exit_button"
        android:text = "@string/fourth_label" 
        android:background="@drawable/and_button" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft = "@dimen/pad_horizontal"
        android:paddingRight = "@dimen/pad_horizontal"
        android:paddingTop = "@dimen/pad_vertical"
        android:paddingBottom = "@dimen/pad_vertical"
        android:layout_margin="@dimen/margin"/>
    </TableRow> 
    </TableLayout>

</LinearLayout>

Любая помощь велика.

Ответы [ 2 ]

1 голос
/ 17 июня 2011

Из вашего вопроса неясно, как именно вы хотите, чтобы ваш макет выглядел, но я предполагаю (по крайней мере, из вашего XML), что вам нужно что-то вроде этого:

enter image description here

У меня нет ваших элементов рисования, поэтому я не могу их включить.

Если дело обстоит именно так, то этот макет поможет:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:gravity="center">
    <TextView android:text="Bubb" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <Button android:text="Button" android:id="@+id/button1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button2"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button3"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button4"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>

РЕДАКТИРОВАТЬ: Это выравниваетв вертикальном списке при переключении на альбомную ориентацию:

enter image description here

Если вам требуется горизонтальный список, просто скопируйте этот макет в «res / layout-land» и измените ориентацию во внешнемLinearLayout на «горизонтальный»:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:gravity="center">

, и вы получите это:

enter image description here

0 голосов
/ 17 июня 2011

Возьмите TableLayout в RelativeLayout и установите свойство TableLayout как «Центр размещения в parent = true», или вы можете использовать «Центр размещения горизонтальный = true» в зависимости от ваших требований.

...