Description of the problem:
I have a layout in which I am trying to paste a Bar layout at the bottom. This layout must have above the Bar layout, a View Pager that covers from the top (top) to where the bar layout begins.
What did I try to do?
To achieve this, I tried to create a vertical constraint from the bottom of the view pager to the top of the bar layout and assigned a layout_height="0dp" to my view pager to act as a match_constraint . The problem is that the view pager took the 0dp seriously by making that the height of the view pager, instead of stretching it down.
Attached is a graphical representation of the problem:
I want my layout to look like in Photo 2 but it is looking like in Photo 1 .
I attach the code of my design
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.ui.CHAT.fragment_contenedor_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/ayuda">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#eeeeee"
android:contentDescription="@string/ayuda">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_datos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/ayuda"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pagerr_perfil"
android:layout_width="match_parent"
android:layout_height="0dp"
android:contentDescription="@string/ayuda"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="@id/bar_layout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/ayuda"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabss_perfil"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:contentDescription="@string/ayuda"
app:tabIndicatorColor="#03a9f4"
app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>
Thanks so much for reading!
Is it necessary to use
ConstraintLayout
? Because if not, you can replace theLinearLayout
and theConstraintLayout
with aRelativeLayout
(I would also recommend that theDrawerLayout
not have so many nested elements, this in order to improve the readability of the code and it will always be easier to modify the less nested the elements are) .With the use of
RelativeLayout
you get what you are looking for.