2x3 пользовательская раскладка сетки не подходит для TableRow - PullRequest
2 голосов
/ 03 января 2012

Я занимаюсь разработкой какого-то плеера с сеткой пользовательских кнопок 2x3 ... Кнопки создаются в customplayerbutton.xml, а затем они используются как «include» в main.xml. Существует проблема с макетом - мои пользовательские кнопки делают не подходит к TableRow:

плохой макет http://img841.imageshack.us/img841/6492/badlayout.png

Что я делаю не так?

customplayerbutton.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:drawable/btn_default"
    android:clickable="true"
    android:focusable="true"
    android:longClickable="true"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2.0"
        android:gravity="center"
        android:text="Track67890"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2.0"
        android:gravity="center"
        android:text="99:99:999 / 99:99:999"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.1" />

</LinearLayout>

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:longClickable="true"
    android:stretchColumns="*" >

    <TableRow
            android:id="@+id/TableRow01"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" >

            <include
                    android:id="@+id/include01"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_gravity="left"
                    layout="@layout/customplayerbutton" />

            <include
                    android:id="@+id/include1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_gravity="right"
                    layout="@layout/customplayerbutton" />
    </TableRow>

    <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" >

            <include
                    android:id="@+id/include02"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    layout="@layout/customplayerbutton" />

            <include
                    android:id="@+id/include04"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    layout="@layout/customplayerbutton" />
    </TableRow>

    <TableRow
            android:id="@+id/TableRow02"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" >

            <include
                    android:id="@+id/include03"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    layout="@layout/customplayerbutton" />

            <include
                    android:id="@+id/include05"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    layout="@layout/customplayerbutton" />
    </TableRow>

</TableLayout>

Ответы [ 2 ]

1 голос
/ 04 января 2012

Наконец, я решил эту проблему, заменив TableLayout на LinearLayout.Вот XML работал мне:

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

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" >

            <include
                    android:id="@+id/include01"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    layout="@layout/customplayerbutton" />

            <include
                    android:id="@+id/include00"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    layout="@layout/customplayerbutton" />
    </LinearLayout>

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" >

            <include
                    android:id="@+id/include02"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    layout="@layout/customplayerbutton" />

            <include
                    android:id="@+id/include04"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    layout="@layout/customplayerbutton" />
    </LinearLayout>

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" >

            <include
                    android:id="@+id/include03"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    layout="@layout/customplayerbutton" />

            <include
                    android:id="@+id/include05"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    layout="@layout/customplayerbutton" />
    </LinearLayout>

</LinearLayout>
0 голосов
/ 04 января 2012

Я протестировал размещенные вами XML-макеты, я не получил вывод, как вы показали здесь, но я получил по-другому.Затем я удалил 2 оператора из файла main.xml, теперь вывод хороший.

Попробуйте это.

В 1-м <TableRow> 1-м <include> удалите строку android:layout_gravity="left" и 2-й <include> удалить строку android:layout_gravity="right"

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...