Как я могу достичь горизонтальной ориентации внутри вертикали в XML - PullRequest
0 голосов
/ 15 мая 2019

У меня есть файл макета, который используется для раздувания представления списка.Поэтому я хочу изменить способ отображения TextView внутри моего LinearLayout.В настоящее время Textview, отображающий текст «localhost», находится в горизонтальной ориентации с двумя другими TextView, которые отображают IP-адрес и MAC-адрес.TextView с ip add и mac находятся в вертикальной ориентации друг с другом. см. Снимок экрана здесь. Я хочу изменить его так, чтобы Textview, отображающий "localhost", находился в вертикальной ориентации, а ip add и macview textview находились рядом друг с другом.что-то вроде этого localhost.net.com 192.168.1.2 |00: 23: ff: 33: ee: 21 Я не хочу помещать текстовое представление localhost в строку само по себе, так как это отразится на моем дизайне кода.вот код для файла макета

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

    <LinearLayout
        android:id="@+id/text_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/host_icon"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.15"
            android:padding="7dp"
            android:src="@drawable/ic_computer_white_36dp"/>

        <TextView
            android:id="@+id/host_name"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.35"
            android:textSize="18sp"
            android:text="LOCALHOST"
            android:padding="10dp" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.45"
            android:orientation="vertical"
            android:paddingLeft="0dp">

            <TextView
                android:id="@+id/ip_address"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                tools:text="192.168.10.100"
                />

            <TextView
                android:id="@+id/mac_address"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="16sp"
                tools:text="aa:bb:cc:00:11:22"
                />

        </LinearLayout>

        <ImageView
            android:id="@+id/port_scan_arrow"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.10"
            android:padding="5dp"
            android:src="@drawable/ic_next_button"/>

    </LinearLayout>
</RelativeLayout>

1 Ответ

1 голос
/ 15 мая 2019

В Android надувание представлений - довольно тяжелая операция, и использование многих макетов не очень эффективно.Попробуйте использовать ConstraintLayout, когда у вас есть разметка макетов.

https://developer.android.com/reference/android/support/constraint/ConstraintLayout https://developer.android.com/training/constraint-layout

...