Как точно выровнять элементы в макете таблицы? - PullRequest
0 голосов
/ 05 июля 2018

У меня проблема с выравниванием элементов таблицы. enter image description here

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

это xml:

<TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Notes"
                    android:layout_column="1"/>

                <TextView
                    android:id="@+id/txt_notes"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_column="2"
                    android:singleLine="false"
                    android:layout_weight="1"
                    android:maxLines="4"/>

            </TableRow>

Я уже пытался установить двоеточие в новом текстовом представлении, но это ничего.

поэтому я попытался добавить двоеточие вместе с setText в Java, Это класс Java:

orderListViewHolder.txtDate.setText(": "+itemOrderList.get(position).getDate());
        orderListViewHolder.txtOrderNumber.setText(": "+itemOrderList.get(position).getOrderNumber());
        orderListViewHolder.txtCustomerName.setText(": "+itemOrderList.get(position).getCustomerName());
        orderListViewHolder.txtProductStatus.setText(": "+itemOrderList.get(position).getProductStatus());
        orderListViewHolder.txtNotes.setText(": "+itemOrderList.get(position).getNotes());

как я могу точно выровнять эти элементы?

Ответы [ 2 ]

0 голосов
/ 05 июля 2018

В соответствии с вашей проблемой, вы должны использовать любой базовый линейный макет с горизонтальной ориентацией.

Пожалуйста, посмотрите

  <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Notes :"
                android:textSize="12sp"
                android:layout_weight="1"
                android:layout_margin="5dp"
                android:gravity="left"
                android:textColor="@android:color/black"/>

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:padding="2dp"
                tools:text="Motor Bekas Honda Supra X"
                android:layout_weight="1"
                android:textSize="12sp"
                android:layout_margin="5dp"
                android:gravity="left"
                android:textColor="@android:color/black"/>

        </LinearLayout>

Но все же, если вы хотите использовать макет таблицы, пожалуйста, попробуйте ниже образец

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:gravity="left"
            android:padding="5dp"
            android:text="Notes :"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:gravity="left"
            android:padding="2dp"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            tools:text="Motor Bekas Honda Supra X ,Motor Bekas Honda Supra X,Motor Bekas Honda Supra X" />


    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:gravity="left"
            android:padding="5dp"
            android:text="Any xyz :"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:gravity="left"
            android:padding="2dp"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            tools:text="Motor Bekas Honda Supra" />


    </TableRow>


</TableLayout>

Скриншоты:

enter image description here

0 голосов
/ 05 июля 2018

Я попробовал ваш макет, и он отлично работает, если вы вставляете TextView с текстом : между 2 TextView:

        <TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="right">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Notes"
        android:layout_column="1"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=":"
        android:layout_column="2"/>

    <TextView
        android:id="@+id/txt_notes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_column="3"
        android:singleLine="false"
        android:layout_weight="1"
        android:maxLines="4"/>

</TableRow>
...