Как разместить TextView
ниже ListView
?
Я когда в Android Studio смотрю на дизайн приложения, listView
занимает всё место, и я не могу поставить свой textView
ниже него.
Stack Overflow на русском — это сайт вопросов и ответов для программистов. Присоединяйтесь! Регистрация займёт не больше минуты.
Присоединиться к сообществуКак разместить TextView
ниже ListView
?
Я когда в Android Studio смотрю на дизайн приложения, listView
занимает всё место, и я не могу поставить свой textView
ниже него.
Разметка для 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>
В результате в обоих случаях получится примерно следующее:
Как один из вариантов:
Корневой LinearLayout(vertival) и в нем:
-ListView
-TextView
Как один из вариантов сделать 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"/>