Hi I have a layout which I want to use multiple times
but when I use include it only appears once, I looked online but could not get an answer
could you suggest what am I doing wrong here please
thanks in advance
R
my common layout
denomination_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/tv_denomination"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:hint="£0.00"
app:layout_constraintBottom_toBottomOf="#+id/et_denomination_count"
app:layout_constraintEnd_toStartOf="#+id/et_denomination_count"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/et_denomination_count" />
<EditText
android:id="#+id/et_denomination_count"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:hint="0"
android:inputType="number"
app:layout_constraintEnd_toStartOf="#+id/tv_denomination"
app:layout_constraintStart_toEndOf="#+id/tv_denomination_total"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tv_denomination_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="£0.00"
app:layout_constraintBottom_toBottomOf="#+id/et_denomination_count"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/et_denomination_count"
app:layout_constraintTop_toTopOf="#+id/et_denomination_count" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondFragment">
<TextView
android:id="#+id/tv_Cash_in_till"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cash in till"
android:layout_marginVertical="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="#+id/denomination_fifty"
layout="#layout/denominations_layout"
app:layout_constraintTop_toBottomOf="#+id/tv_Cash_in_till" />
<include
android:id="#+id/denomination_twenty"
layout="#layout/denominations_layout"
app:layout_constraintTop_toBottomOf="#+id/denomination_fifty" />
<Button
android:id="#+id/button_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/previous"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
You can try to put each inside and set required sizes already on FrameLayout
<FrameLayout
android:id="#+id/denomination_fifty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/tv_Cash_in_till">
<include
layout="#layout/denominations_layout" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/denomination_fifty">
<include
android:id="#+id/denomination_twenty"
layout="#layout/denominations_layout" />
</FrameLayout>
To make constraints work, you must add layout_width and layout_height to <include tag.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondFragment">
<TextView
android:id="#+id/tv_Cash_in_till"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="18dp"
android:text="Cash in till"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="#+id/denomination_fifty"
layout="#layout/denominations_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/tv_Cash_in_till" />
<include
android:id="#+id/denomination_twenty"
layout="#layout/denominations_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/denomination_fifty" />
<Button
android:id="#+id/button_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/previous"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Related
I was using Constraint layout in a fragment. I had set TopToBottomOf although it wasn't reaching to bottom.
<Spinner
android:id="#+id/filterSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewCallLog"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/filterSpinner" />
I had set it app:layout_constraintTop_toBottomOf="#+id/filterSpinner". I want to put recyclerView on bottom of Spinner. I want to achieve it without margin.
Seems like constraint layout isn't working in the page. Hence I am showing the whole xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_marginTop="30dp"
android:layout_height="match_parent"
tools:context=".fragment.DialerFragment">
<Spinner
android:id="#+id/filterSpinner"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewCallLog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/filterSpinner" />
<com.futuremind.recyclerviewfastscroll.FastScroller
android:id="#+id/fastscroll_dialer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
app:fastscroll__bubbleColor="#5e64ce"
app:fastscroll__handleColor="#8f93d1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#id/recyclerViewCallLog"
app:layout_constraintTop_toTopOf="#+id/recyclerViewCallLog" />
</androidx.constraintlayout.widget.ConstraintLayout>
You just need to do 0dp height for RecyclerView. like below
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_marginTop="30dp"
android:layout_height="match_parent">
<Spinner
android:id="#+id/filterSpinner"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewCallLog"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/filterSpinner" />
<com.futuremind.recyclerviewfastscroll.FastScroller
android:id="#+id/fastscroll_dialer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
app:fastscroll__bubbleColor="#5e64ce"
app:fastscroll__handleColor="#8f93d1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#id/recyclerViewCallLog"
app:layout_constraintTop_toTopOf="#+id/recyclerViewCallLog" />
</androidx.constraintlayout.widget.ConstraintLayout>
I am trying to create a square LinearLayout container of id imgContainer within a ScrollView element, but I am unable to do so because the app:layout_constraintDimensionRatio doesn't seem to be working. Using the following xml code, the imgContainer renders with a height of 0dp:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/imgContainer"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/trackName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:text="Test Name"
android:textSize="25dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imgContainer" />
<!-- Other stuff -->
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
However, when I move the imgContainer out of the ScrollView like so, the imgContainer is square-shaped as expected.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/imgContainer"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView
...>
<!-- Same as above -->
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
I also tried moving out of the LinearLayout it is nested in while still having it within the ScrollView, but that didn't work either. If anyone knows how to fix this, and why this happens, that would be great. Thanks in advance.
app:layout_constraint.. only work under <androidx.constraintlayout.widget.ConstraintLayout
you can try the following:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/imgContainer"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/trackName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:text="Test Name"
android:textSize="25dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imgContainer" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I have tried the below code but all the time its giving me the recyclerview as full screen any idea how to solve this.
Note i have only two rows/items in my recyclerview
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="#layout/recyclerview_item" />
</RelativeLayout>
<EditText
android:id="#+id/textfield"
android:layout_width="294dp"
android:layout_height="53dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
android:layout_marginBottom="164dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent">
</EditText>
</androidx.constraintlayout.widget.ConstraintLayout>
Yes you can do it with constraint layout here is the code you can follow
Note: Please do clean & Rebuild Project to reflect the correct UI changes i have noticed in Android Studio 3.5+ sometimes the UI doesn't reflect.
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="0dp"
tools:listitem="#layout/recyclerview_item"
app:layout_constraintBottom_toTopOf="#id/textfield"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/textfield"
android:layout_width="196dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="164dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/button"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/recyclerview1" />
</androidx.constraintlayout.widget.ConstraintLayout>
Easiest way to implement this by using relativelayout.
Just replace your code with this.
<RelativeLayout
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">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="#layout/recyclerview_item"
android:layout_above="#id/textfield"//Recyclerview will take above area.
/>
<EditText
android:id="#+id/textfield"
android:layout_width="294dp"
android:layout_height="53dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
android:layout_marginBottom="164dp"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Try below layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:id="#+id/recyclerview_layout"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="#layout/recyclerview_item" />
</RelativeLayout>
<EditText
android:id="#+id/textfield"
android:layout_width="294dp"
android:layout_height="53dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
app:layout_constraintTop_toBottomOf="#+id/recyclerview_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
</EditText>
</androidx.constraintlayout.widget.ConstraintLayout>
recyclerview_item should use wrap_content as layout_height
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"> <!--Should be wrap_content-->
<!--Here list item content-->
</LinearLayout>
Output:
You can also achieve this by simply use LinearLayout like below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:id="#+id/recyclerview_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="#layout/recyclerview_item" />
</RelativeLayout>
<EditText
android:id="#+id/textfield"
android:layout_width="294dp"
android:layout_height="53dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp">
</EditText>
</LinearLayout>
Here is how to do it correctly:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="0dp"
tools:listitem="#layout/recyclerview_item"
app:layout_constraintBottom_toTopOf="#id/textfield"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/textfield"
android:layout_width="294dp"
android:layout_height="53dp"
android:layout_marginStart="80dp"
android:layout_marginEnd="80dp"
android:layout_marginBottom="164dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/recyclerview1" />
</androidx.constraintlayout.widget.ConstraintLayout>
I hope this is what you are looking for.
I want to align button for right in the middle of TextView like WhatsApp. Android studio's layout preview screen is showing right but at phone it is not align middle of TextView, align bottom of screen.
No problem with fragment alone but when fragment inside activity, problem occurs. I understand that my activity layout is wrong.
How can I align send button?
Whatsapp button:
My button at Android Studio preview:
My button at phone:
my fragment layout:
<?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="match_parent"
android:background="#color/colorBlue"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/userNames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="10dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:text="Hello Nilu Pilu"
android:textColor="#color/colorGreen" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:contentDescription="#null"
android:src="#drawable/ic_log_out" />
</RelativeLayout>
my activity layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/colorPrimary"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
app:tabMode="scrollable">
<androidx.appcompat.widget.SearchView
android:id="#+id/search_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="#null"
android:iconifiedByDefault="false"
android:tint="#color/white"
app:defaultQueryHint="#string/searchForName"
app:iconifiedByDefault="false"
app:queryHint="#string/searchForName"
app:srcCompat="#drawable/ic_search_24" />
</androidx.appcompat.widget.Toolbar>
<LinearLayout
android:id="#+id/share_list_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="MergeRootFrame" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
NO need to use nested RelativeLayout you can achieve it only using single RelativeLayout
Try this using RelativeLayout
<?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="match_parent"
android:background="#color/colorBlue"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/userNames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="10dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:text="Hello Nilu Pilu"
android:textColor="#color/colorGreen" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:contentDescription="#null"
android:src="#drawable/ic_log_out" />
</RelativeLayout>
Try this using ConstraintLayout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBlue"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/userNames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="10dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:text="Hello Nilu Pilu"
android:textColor="#color/colorGreen"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:contentDescription="#null"
android:src="#drawable/ic_log_out"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT
I suggest use ConstraintLayout layout instead of RelativeLayout and here is your code with ConstraintLayout, which will work perfectly.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/emptyListColor"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#+id/bottomView"
android:layout_height="0dp" />
<RelativeLayout
android:id="#+id/bottomView"
android:layout_width="match_parent"
android:layout_height="40dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:padding="5dp">
<TextView
android:id="#+id/userNames"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start|center_vertical"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="5dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:textColor="#color/white" />
</RelativeLayout>
<ImageView
android:id="#+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
app:layout_constraintTop_toTopOf="#+id/bottomView"
app:layout_constraintBottom_toTopOf="#+id/bottomView"
app:layout_constraintEnd_toEndOf="#+id/bottomView"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="#drawable/send_circle"
android:contentDescription="#null"
android:src="#drawable/attach_send2" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have my layout setup as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="#layout/my_toolbar" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.my.SubView
android:id="#+id/my_list_subview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="#+id/text_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/padding_medium"
android:layout_margin="#dimen/padding_medium"
android:text="Hello"
android:textSize="14sp"
android:maxLines="3"/>
</LinearLayout>
The problem is that the SwipeRefreshLayout takes up the entire screen and the textview doesn't show up at all.
The blue line in the above image is where the text view is. Is there anything I am missing? This seems to be so simple a problem, its ludicrous!
Image 2 in response to the answer by #Tomar
try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/my_toolbar"
android:id="#+id/top_layout"/>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_above="#+id/text_content"
android:layout_below="#+id/top_layout"
android:layout_height="wrap_content">
<com.my.SubView
android:id="#+id/my_list_subview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="#+id/text_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/padding_medium"
android:layout_margin="#dimen/padding_medium"
android:text="Hello"
android:textSize="14sp"
android:layout_alignParentBottom="true"
android:maxLines="3"/>
</RelativeLayout>
As I mentioned above, I worked it out with ConstraintLayout as below. I do not know why I need to use a large bottom margin and padding in the swipe refresh layout for it to sit above the text. Without these, it doesn't work!
<android.support.constraint.ConstraintLayout 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:background="#color/white"
xmlns:app="http://schemas.android.com/apk/res-auto">
<include layout="#layout/toolbar"
android:id="#+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/padding_large"
android:paddingBottom="#dimen/padding_super_large"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"
app:layout_constraintBottom_toTopOf="#+id/text_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<com.my.SubView
android:id="#+id/my_list_subview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/white"/>
</android.support.v4.widget.SwipeRefreshLayout>
<EditText
android:id="#+id/text_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/white"
android:hint="#string/write_message"
android:textSize="14sp"
android:maxLines="3"
android:padding="#dimen/padding_medium"
android:paddingLeft="#dimen/padding_large"
app:layout_constraintTop_toBottomOf="#+id/swipe_refresh"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:visibility="visible"
tools:layout_editor_absoluteX="0dp" />
</android.support.constraint.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/srl_reload_list"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView_openOrderList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>