Как разместить TextView над ListView внутри Linear Layout - PullRequest
0 голосов
/ 28 июня 2018

Я пытаюсь разместить TextView над ListView внутри линейного макета, но быстро не добираюсь .. Я пытался поместить телевизор в его собственный макет, я пытался добавить поле в верхней части LV, но, кажется, ничего не работает Пожалуйста, смотрите скриншот и .XML ниже

Дизайн Посмотреть макет

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:id="@+id/setting_frag"
    android:baselineAligned="false">


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="hello"/>

    <ListView
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:background="?attr/colorBackgroundFloating"
        android:descendantFocusability="blocksDescendants" />


    <RelativeLayout
        android:id="@+id/setting_dialogue"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/device_info_stub"
            android:inflatedId="@+id/device_info_stub_inflated_id"
            android:layout="@layout/device_info"
            />
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/health_check_stub"
            android:inflatedId="@+id/health_check_stub_inflated_id"
            android:layout="@layout/health_checks"
            />
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/system_config_stub"
            android:inflatedId="@+id/system_config_stub_inflated_id"
            android:layout="@layout/system_configuration"
            />
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/database_stats_stub"
            android:inflatedId="@+id/database_stats_stub_inflated_id"
            android:layout="@layout/database_stats"
            />
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/check_update_stub"
            android:inflatedId="@+id/device_info_stub_inflated_id"
            android:layout="@layout/device_info"
            />

    </RelativeLayout>

Скриншот

Новый скриншот

Ответы [ 2 ]

0 голосов
/ 28 июня 2018
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weight_sum ="11"
    android:id="@+id/setting_frag"
    android:baselineAligned="false">


<TextView
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:text="hello"
    android:layout_weight="2"/>

    <ListView
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:background="?attr/colorBackgroundFloating"
        android:descendantFocusability="blocksDescendants" />


    <RelativeLayout
        android:id="@+id/setting_dialogue"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4">
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/device_info_stub"
            android:inflatedId="@+id/device_info_stub_inflated_id"
            android:layout="@layout/device_info"
            />
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/health_check_stub"
            android:inflatedId="@+id/health_check_stub_inflated_id"
            android:layout="@layout/health_checks"
            />
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/system_config_stub"
            android:inflatedId="@+id/system_config_stub_inflated_id"
            android:layout="@layout/system_configuration"
            />
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/database_stats_stub"
            android:inflatedId="@+id/database_stats_stub_inflated_id"
            android:layout="@layout/database_stats"
            />
        <ViewStub
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/check_update_stub"
            android:inflatedId="@+id/device_info_stub_inflated_id"
            android:layout="@layout/device_info"
            />

    </RelativeLayout>

Я внес изменения. Это будет работать для вас.

0 голосов
/ 28 июня 2018

изменить android:orientation="horizontal" на android:orientation="vertical"


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

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/setting_frag"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:baselineAligned="false"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:baselineAligned="false"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#F00"
            android:textColor="@color/white"
            android:text="hello" />


        <ListView
            android:id="@+id/lv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#0F0"
            android:descendantFocusability="blocksDescendants" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/setting_dialogue"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#00F"
        android:layout_weight="1">

        <ViewStub
            android:id="@+id/device_info_stub"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:inflatedId="@+id/device_info_stub_inflated_id"
            android:layout="@layout/activity_burst_assignees" />

        <ViewStub
            android:id="@+id/health_check_stub"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:inflatedId="@+id/health_check_stub_inflated_id"
            android:layout="@layout/activity_burst_assignees" />

        <ViewStub
            android:id="@+id/system_config_stub"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:inflatedId="@+id/system_config_stub_inflated_id"
            android:layout="@layout/activity_burst_assignees" />

        <ViewStub
            android:id="@+id/database_stats_stub"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:inflatedId="@+id/database_stats_stub_inflated_id"
            android:layout="@layout/activity_burst_assignees" />

        <ViewStub
            android:id="@+id/check_update_stub"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:inflatedId="@+id/device_info_stub_inflated_id"
            android:layout="@layout/activity_burst_assignees" />

    </RelativeLayout>


</LinearLayout>

Вывод кода будет выглядеть ниже

...