1

Как разместить TextView ниже ListView?

Я когда в Android Studio смотрю на дизайн приложения, listView занимает всё место, и я не могу поставить свой textView ниже него.

3
  • 1
    уточните, не понятно в чем трудность.
    – Likhanov
    10 янв 2018 в 16:24
  • 1
    наверное вы имеете в виду footer startandroid.ru/ru/uroki/vse-uroki-spiskom/… 10 янв 2018 в 17:20
  • @Likhanov Я когда в android studio смотрю на дизайн приложения - listView занимает всё место , и я не могу поставить свой textView ниже него . 10 янв 2018 в 21:38

3 ответа 3

2

Разметка для ListView на весь экран и под ним TextView на стандартную высоту wrap_content.

С помощью LinearLayout:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:text="some text" />
</LinearLayout>

С помощью ConstraintLayout:

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/listView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/textView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="some text"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>
</android.support.constraint.ConstraintLayout>

В результате в обоих случаях получится примерно следующее:

scrn

1

Как один из вариантов:

Корневой LinearLayout(vertival) и в нем:
  -ListView
  -TextView
1

Как один из вариантов сделать LinearLayout и распределить в нём вес каждого компонента. Распределение пространства рассчитывается как вес текущего компонента, делённый на общий вес всех компонентов умноженный на размер родительского layout.

В примере ниже 1/2 * size

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"/>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.