Столбцы в TableRow, разделенные с использованием весов и весовых коэффициентов, которые не располагаются должным образом. - PullRequest
0 голосов
/ 27 февраля 2012

Мне было поручено создать действие, которое отображает таблицу изменений, внесенных в приложение по версии. Таблица имеет четыре столбца: Id, Type, Description и Version.

Для этого я поместил TableLayout в scrollView. Затем у меня есть шаблон для TableRows, которые динамически раздуваются во время выполнения. Ширина столбцов должна оставаться неизменной; они могут переполняться по высоте, но не по ширине.

Чтобы достичь этого, я попытался использовать свойство weight & weight: sum столбца и контейнера строки соответственно. Я установил layout_width на 0 на обоих.

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

(Пейзаж выглядит близко, но вы можете видеть, что внешняя граница все еще отрезана).

Я заметил, что если вес детей составляет примерно 45% от общего веса, то вес приближается к правильному взгляду.

Наконец, видам, разделяющим столбцы, был присвоен вес ноль и ширина 1 дюйм. (Я не уверен, что это может вызвать проблемы).

Мне кажется, что при взвешивании используется ширина, как если бы она была в ландшафтном режиме. Должен ли я сделать два макета, один для портрета и один для пейзажа?

Я добавил макет XML для строки таблицы:

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

    <LinearLayout
        android:id="@+id/table_row_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <View
            android:id="@+id/top_border"
            android:layout_width="match_parent"
            android:layout_height="1dip"
            android:background="#FFFFFF" />

        <LinearLayout
            android:id="@+id/horizontal_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="4" >

            <View
                android:id="@+id/view1"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_id"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Id" android:textSize="10sp" android:layout_weight="0.5"/>

            <View
                android:id="@+id/view2"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_type"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Type" android:textSize="10sp" android:layout_weight="1"/>

            <View
                android:id="@+id/view3"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_desc"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Description" android:textSize="10sp" android:layout_weight="2"/>

            <View
                android:id="@+id/view4"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_version"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Version" android:textSize="10sp" android:layout_weight="0.5"/>

            <View
                android:id="@+id/view6"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>
        </LinearLayout>

        <View
            android:id="@+id/view7"
            android:layout_width="match_parent"
            android:layout_height="1dip" android:background="#FFFFFF"/>

    </LinearLayout>

</TableRow>

Верхний и нижний вид - это верхняя и нижняя границы.

И вот макет таблицы, к которой добавляется и она:

<?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" android:scrollbarAlwaysDrawVerticalTrack="true">

    <ScrollView
        android:id="@+id/view_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" android:fillViewport="true">

        <TableLayout
            android:id="@+id/table_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:shrinkColumns="0"
            android:stretchColumns="0" >
        </TableLayout>

    </ScrollView>

</LinearLayout> 

1 Ответ

1 голос
/ 07 марта 2012

Спасибо, МЗ.

Извините, что не вернулся к вам раньше.(Я новичок в Android и Stack Overflow ... и я не понял, что вы ответили на мой вопрос.) Я добавил макет строки.

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

    <LinearLayout
        android:id="@+id/table_row_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <View
            android:id="@+id/top_border"
            android:layout_width="match_parent"
            android:layout_height="1dip"
            android:background="#FFFFFF" />

        <LinearLayout
            android:id="@+id/horizontal_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="4" >

            <View
                android:id="@+id/view1"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_id"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Id" android:textSize="10sp"       android:layout_weight="0.20"/>

            <View
                android:id="@+id/view2"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_type"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Type" android:textSize="10sp" android:layout_weight="0.5"/>

            <View
                android:id="@+id/view3"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_desc"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Description" android:textSize="10sp" android:layout_weight="1"/>

            <View
                android:id="@+id/view4"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_version"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Version" android:textSize="10sp" android:layout_weight="0.25"/>

            <View
                android:id="@+id/view6"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>
        </LinearLayout>

        <View
            android:id="@+id/view7"
            android:layout_width="match_parent"
            android:layout_height="1dip" android:background="#FFFFFF"/>

    </LinearLayout>

</TableRow>

Дэвид

...