Solution 1 :
following solution worked for me:-
<?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"
xmlns_app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/relative">
<androidx.appcompat.widget.Toolbar
android_layout_width="match_parent"
android_layout_height="wrap_content"
app_collapseIcon="@drawable/ic_arrow_back_black_24dp"
android_id="@+id/toolbartable"
android_background="@color/colorPrimaryDark">
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/nest"
android_scrollbars="vertical"
android_layout_below="@id/relative">
<RelativeLayout
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_nestedScrollingEnabled="false"
android_id="@+id/recyleview"/>
<LinearLayout
android_layout_width="match_parent"
android_layout_height="100dp"
android_id="@+id/linearlayoutorder"
android_layout_below="@id/recyleview"
android_orientation="horizontal"
android_weightSum="2"
android_background="@drawable/border"
android_backgroundTintMode="@color/colorPrimary">
<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_text="TOTAL"
android_layout_gravity="center"
android_layout_weight="1"></TextView>
<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_weight="1"
android_id="@+id/totalidcost"
android_layout_gravity="right|center"
android_textAlignment="textEnd"
tools_ignore="RtlCompat"></TextView>
</LinearLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
Solution 2 :
You haven’t added weightSum and orientation values for LinearLayout.
Solution 3 :
You can use a NestedScrollView instead of the ScrollView. And also put your RecyclerView as well as the LinearLayout inside the NestedScrollView. And enable android:nestedScrollingEnabled=true
. Should work for you.
<NestedScrollView
android_layout_width="match_parent"
android_layout_height="match_parent"
android_nestedScrollingEnabled=true>
<LinearLayout
android_layout_width="match_parent"
android_layout_height="match_parent"
android_orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android_id="@+id/recyleview"
android_layout_width="match_parent"
android_layout_height="0dp"
app_layout_constraintBottom_toTopOf="@id/linearlayoutorder"
app_layout_constraintTop_toBottomOf="@id/relative" />
<LinearLayout
android_id="@+id/linearlayoutorder"
android_layout_width="match_parent"
android_layout_height="100dp"
android_background="#000000"
android_backgroundTintMode="@color/colorPrimary"
android_orientation="horizontal"
android_weightSum="2"
app_layout_constraintBottom_toBottomOf="parent"
app_layout_constraintLeft_toLeftOf="parent"
app_layout_constraintRight_toRightOf="parent">
<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="center"
android_layout_weight="1"
android_text="TOTAL" />
<TextView
android_id="@+id/totalidcost"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="right|center"
android_layout_weight="1"
android_textAlignment="textEnd"
tools_ignore="RtlCompat" />
</LinearLayout>
</LinearLayout>
And in your java class where you have your recyclerview set recyclerView.setNestedScrollingEnabled(true or false);
Solution 4 :
Use ConstraintLayout like this way, Here is full xml code what you need
<?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">
<RelativeLayout
android_id="@+id/relative"
android_layout_width="match_parent"
android_layout_height="wrap_content"
app_layout_constraintLeft_toLeftOf="parent"
app_layout_constraintRight_toRightOf="parent"
app_layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android_id="@+id/toolbartable"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_background="@color/colorPrimaryDark"
app_collapseIcon="@drawable/back" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android_id="@+id/recyleview"
android_layout_width="match_parent"
android_layout_height="0dp"
app_layout_constraintBottom_toTopOf="@id/linearlayoutorder"
app_layout_constraintTop_toBottomOf="@id/relative" />
<LinearLayout
android_id="@+id/linearlayoutorder"
android_layout_width="match_parent"
android_layout_height="100dp"
android_background="#000000"
android_backgroundTintMode="@color/colorPrimary"
android_orientation="horizontal"
android_weightSum="2"
app_layout_constraintBottom_toBottomOf="parent"
app_layout_constraintLeft_toLeftOf="parent"
app_layout_constraintRight_toRightOf="parent">
<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="center"
android_layout_weight="1"
android_text="TOTAL" />
<TextView
android_id="@+id/totalidcost"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="right|center"
android_layout_weight="1"
android_textAlignment="textEnd"
tools_ignore="RtlCompat" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Problem :
in my layout i have recyclerview of product listing..below that im displaying total price in linearlayout …but on scroll linearlayout is not displaying
sceneorio of my code:
1–> when i have one item on recyclerview –>linearlayout displays fine
2–> when i have more items on recyclerview –>on scrolling down linearlayout cant be seen(linear layout is not displaying)
need help in second sceneorio…thanks in advance
Following here is code xml:–
<?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"
xmlns_app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/relative">
<androidx.appcompat.widget.Toolbar
android_layout_width="match_parent"
android_layout_height="wrap_content"
app_collapseIcon="@drawable/ic_arrow_back_black_24dp"
android_id="@+id/toolbartable"
android_background="@color/colorPrimaryDark">
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<ScrollView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_layout_below="@id/relative"
android_id="@+id/nest"
android_scrollbars="vertical">
<androidx.recyclerview.widget.RecyclerView
android_layout_width="match_parent"
android_layout_below="@id/relative"
android_layout_height="wrap_content"
android_id="@+id/recyleview"/>
</ScrollView>
<LinearLayout
android_layout_width="match_parent"
android_layout_height="100dp"
android_id="@+id/linearlayoutorder"
android_layout_below="@id/nest"
android_orientation="horizontal"
android_weightSum="2"
android_background="@drawable/border"
android_backgroundTintMode="@color/colorPrimary">
<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_text="TOTAL"
android_layout_gravity="center"
android_layout_weight="1"></TextView>
<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_weight="1"
android_id="@+id/totalidcost"
android_layout_gravity="right|center"
android_textAlignment="textEnd"
tools_ignore="RtlCompat"></TextView>
</LinearLayout>
</RelativeLayout>
Updated code:–
<?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"
xmlns_app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/relative">
<androidx.appcompat.widget.Toolbar
android_layout_width="match_parent"
android_layout_height="wrap_content"
app_collapseIcon="@drawable/ic_arrow_back_black_24dp"
android_id="@+id/toolbartable"
android_background="@color/colorPrimaryDark">
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_id="@+id/nest"
android_scrollbars="vertical"
android_layout_below="@id/relative">
<androidx.recyclerview.widget.RecyclerView
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_nestedScrollingEnabled="false"
android_id="@+id/recyleview"/>
<LinearLayout
android_layout_width="match_parent"
android_layout_height="100dp"
android_id="@+id/linearlayoutorder"
android_orientation="horizontal"
android_weightSum="2"
android_background="@drawable/border"
android_backgroundTintMode="@color/colorPrimary">
<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_text="TOTAL"
android_layout_gravity="center"
android_layout_weight="1"></TextView>
<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_weight="1"
android_id="@+id/totalidcost"
android_layout_gravity="right|center"
android_textAlignment="textEnd"
tools_ignore="RtlCompat"></TextView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
error getting–:Caused by: android.view.InflateException: Binary XML file line #34: ScrollView can host only one direct child
`Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child`
need help
Comments
Comment posted by Seddik Fredj
but if you remove item, it still take the space?
Comment posted by IRON MAN
no i did changes..doesnt worked though… situation is still the same
Comment posted by Arda Kazancı
You don’t have to use Recyclerview in scroll view.
Comment posted by IRON MAN
okay after removing scrollview ..situation is still same …not displaying after scrolling recyclerview
Comment posted by IRON MAN
i did nestedscrolling false inside recyclerview i got error ==> Caused by: android.view.InflateException: Binary XML file line #34: ScrollView can host only one direct child Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
Comment posted by KalanaChinthaka
Just create a linearLayout or a RelativeLayout as a parent of your view inside the nestedScrollView. Then you should be fine. I will update my answer with the hierarchy.