Not able show Top & bottom items in recyclerView - android

I am using recyclerview in my project but bottom items are not displayed in recyclerview.
I tried ScrollView but my app is crashing it shows java.lang.IllegalStateException: ScrollView can host only one direct child this error.
Here is my code
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyler_transaction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout></FrameLayout>

<ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RecyclerView
android:id="#+id/rcview"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
Implement your RecyclerView in this manner. You dont need ScrollView to add recyclerview. Recyclerview can scroll by itself.
It will be good of you can add your whole xml and Adapter code.

I think you use the recyclerview as parent layout that this work is wrong, because recyclerview in android just get a adapter that it, and you most use the container layout like scrollbars for show another layout inside it.

You have added more than one ViewGroup as a child of your ScrollView. ScrollView must contain at most one child in order to properly calculate the height of the view.
Below sample code is wrong:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
....
....
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
....
....
</LinearLayout>
</ScrollView>
In order to solve the problem, you can use the below sample code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- here add your views -->
....
....
</LinearLayout>
</ScrollView>

Related

RecyclerView content goes behind and not over TextView above

Consider this video from material design on drag & dropping items:
Material design reordering list
In the video you see a RecyclerView and above it a TextView with the text "Playlist". When the row is dragged up you see it going over the Playlist.
In my code the row goes behind the Textview. I've put RecyclerView's layout_height to match_parent. And I used a FrameLayout and placed the TextView below the RecyclerView. Why isn't it going over it?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/general_margin"
android:text="#string/activity_bible_order_explanation"
android:layout_gravity="start|top" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:layout_marginTop="96dp"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</FrameLayout>
Use Constraint layout as a parent layout and add textview at the top by giving top constraints to the textview. then add
recyclerview's top constraint to the the bottom of textview and recyclerview bottom constraint to the bottom of parent then set height 0 it will work
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:padding="#dimen/general_margin"
android:text="#string/activity_bible_order_explanation"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/txtTitle"
android:background="#android:color/transparent"
android:layout_marginTop="96dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.constraintlayout.widget.ConstraintLayout>
Have you tried elevation? the problem might be that in the z axis the TextView is higher than the RecyclerView. try adding android:elevation="10dp" or higher... like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/general_margin"
android:text="#string/activity_bible_order_explanation"
android:layout_gravity="start|top" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="10dp" (if it doesn't work try maybe higher elevation, 20dp etc.)
android:background="#android:color/transparent"
android:layout_marginTop="96dp"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</FrameLayout>
Hope it works for you (: let me know!
What is the parent layout of this?
Because you set match_parent in recyclerview and list have many content that's why this issue facing.
Please give fix height or use relative layout and apply position above of text view in recyclerview
Problem with your layout code:
You're using a FrameLayout
Inside FrameLayout, you're also using top margin on your RecyclerView
android:layout_marginTop="96dp" <-- This causing the issue.
Solution:
You should LinearLayout instead of FrameLayout. And, also set LinearLayout's orientation as vertical.
android:orientation="vertical"
Also remove this line from your RecyclerView:-
android:layout_marginTop="96dp"
Solution Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="Hello World"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
The issue is not that the dragged view is going behind the TextView but, rather, the dragged view is not being drawn outside the bounds of the RecyclerView. The effect is the same.
To allow the RecyclerView to draw outside of itself, set the following for the parent of the RecyclerView:
android:clipChildren="false"
For the RecyclerView set
android:clipToPadding="false"
That should solve the problem.
The RecyclerView is above the text view in your FrameLayout. Currently, it appears that the underlying TextView is above the RecyclerView as you have given the background for the RecyclerView as:
android:background="#android:color/transparent"
To make this work as normal, either remove this line or change the background of RecyclerView to any value other than transparent.
There is 1 more issue. You need to place the recycler view first. Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<TextView
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="Hello World"/>
</LinearLayout>

RecyclerView inside ScrollView, some items are not shown

I had a RecyclerView in ScrollView like this:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--other stuff-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
</LinearLayout>
<!--other stuff-->
</ScrollView>
And the RecyclerView's item is a RelativeLayout, inside of which there is an EditText and other views. The layout_height of that RelativeLayout and EditText is both wrap_content. User can input into that EditText without any limit of length/lines so that each item's height is different.
Then I found that getItemCount() in Adapter returns true value but onBindViewHolder() is called of wrong times(less than it should be), thus not enough to show all items.
I found that this will happen only if I wrote recyclerView.setNestedScrollingEnabled(false). But I cannot remove this line. Because if I did so, the RecyclerView won't scroll smoothly and is not harmonious with other views inside ScrollView and ScrollView itself.
This occurs on 6.0 but not on 4.1.
I communicated with Google at this page: https://code.google.com/p/android/issues/detail?id=213914 and he told me this is a bug fix for RecyclerView. You can visit that page so that you can understand the question and my goal better(There is a small sample project to show the problem there). I don't agree with him even now and I want to solve the problem. Please help, thank you in advance.
I found the solution myself: replace ScrollView with NestedScrollView and keep recyclerView.setNestedScrollingEnabled(false). I don't know if this is what NestedScrollView is made for but it works.
NOTICE:
NestedScrollView is not a child of ScrollView but of FrameLayout.
This solution will also bring some bugs with self-simulated adjustResize.
In my case, I replaced LineaLayout with RelativeLayout and it's solved the issue and all items have shown.
The answer is:
androidx.core.widget.NestedScrollView
In the first step, you need to create NestedScrollView element in XML:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// RecyclerViews should be located here
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Next, add the below attribute to recyclerView:
android:overScrollMode="never"
Then, the recyclerView will be as following:
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />
Finally, the whole the layout will be something like below, you can add other materials inside LinearLayout:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
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:overScrollMode="never" />
// other materials
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Celebrate.............;)
The best solution is to keep multiple Views in a Single View / View Group and then keep that one view in the SrcollView. ie.
Format -
<ScrollView>
<Another View>
<RecyclerView>
<TextView>
<And Other Views>
</Another View>
</ScrollView>
Eg.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="any text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="any text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
Another Eg. of ScrollView with multiple Views
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/CategoryItem"
android:textSize="20sp"
android:textColor="#000000"
/>
<TextView
android:textColor="#000000"
android:text="₹1000"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:textColor="#000000"
android:text="so\nugh\nos\nghs\nrgh\n
sghs\noug\nhro\nghreo\nhgor\ngheroh\ngr\neoh\n
og\nhrf\ndhog\n
so\nugh\nos\nghs\nrgh\nsghs\noug\nhro\n
ghreo\nhgor\ngheroh\ngr\neoh\nog\nhrf\ndhog"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

Android: Recycler view inside ScrollView is not working

I am trying to put RecyclerView inside ScrollView, I Have layout above the recycler view, so I want to scroll both layout and recycler while scrolling.
In My main Layout I have two sub Layout , and one of the have recyclerView and another one Have an Image .Both layout inside a scrollView. When I scrolling up in the layout , I want to scroll both
I know the issue that we cant put two scroll view in one layout.
Am searching is there any logic that we can scroll both layout and recycler View
Layout.xml
<?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="match_parent"
android:background="#color/backgorund"
android:weightSum="1">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="#+id/layout_top_balance"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txt_balance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="35dp"
android:textColor="#color/black"
android:text="$60 USD"/>
<TextView
android:layout_below="#+id/txt_balance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20dp"
android:textColor="#828282"
android:text="Account Balance"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_feeds"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingLeft="16dp"
android:paddingBottom="5dp"
android:layout_weight=".75">
<view
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="android.support.v7.widget.RecyclerView"
android:id="#+id/recycler_view"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Cam any one please help for solving this issue:)
It is not recommended to scroll inside scroll in android. Recycler view is itself a scroll. Seems you want a scrollable portion above a list "layout_top_balance". Add this view as header of recycler view and remove scrollview. This will solve your problem.
You can use this recycle view lib if you want to add header
RecyclerViewHeader Example 1
RecyclerViewHeader Example 2

Android ExpandableListView not showing

So I have a ExpandableListView in my layout, but for some reason It is showing only some part of it when I run the app. Yes, it's "some" part - actually almost the enture first GroupView.
If I set a fixed height to the list at android:layout_height="some dp", instead of android:layout_height="match_parent" I can see the whole list. But, If I have too many group view's and child view's, again, I can see only some part of it (as the height is fixed).
I've tried to put the expandable list inside a LinearLayout, have tried to set android:layout_height="wrap_content", and so on, but without success.
How can I solve this?
Thank you,
<?xml version="1.0" encoding="utf-8"?>
<!-- That's the main layout.-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view_m"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout is here because a ScrollView can only have one child view.-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- That's the second ScrollView. But this one is horizontal.-->
<HorizontalScrollView
android:id="#+id/map_layout"
android:layout_width="match_parent"
android:layout_height="400dp">
<!-- This LinearLayout is here because a ScrollView can only have one child view.-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!-- Some view's here -->
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="#+id/scroll_down"
android:text="Scroll down to see marker info!"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/holo_green_light"
android:background="#android:color/black"/>
<ExpandableListView
android:id="#+id/m_expandable_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ExpandableListView>
</LinearLayout>
</ScrollView>

How to disable RecyclerView scrolling to make the layout listen its ScrollView parent?

I'm trying to put a RecyclerView, inside a ScrollView. But the ScrollView doesn't scrolls and the RecyclerView does but I don't want it to... What can I do?
I tried with this class https://stackoverflow.com/a/30222721/4864104 and in fact the RecyclerView doesn't scroll anymore, but neither does the ScrollView.
Any help to make the ScrollView work even with the disabled RecyclerView? Thanks in advance.
This is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="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="jahirfiquitiva.projects.activities.DeveloperActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<ScrollView
android:id="#+id/osv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar"
android:fillViewport="true"
android:gravity="center"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<ImageView
android:id="#+id/photoJahir"
android:layout_width="144dp"
android:layout_height="144dp"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.2"
android:paddingBottom="#dimen/lists_padding"
android:paddingTop="#dimen/lists_padding"
android:text="#string/developer_bio"
android:textSize="#dimen/abc_text_size_subtitle_material_toolbar" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/dividers_about_section"
android:alpha="0.3"
android:background="#color/primary" />
<RecyclerView
android:id="#+id/buttonsGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/lists_padding"
android:paddingTop="#dimen/lists_padding" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/dividers_about_section"
android:alpha="0.3"
android:background="#color/primary" />
<View
android:layout_width="match_parent"
android:layout_height="72dp" />
</LinearLayout>
</ScrollView>
You could easily achieve it by changing your scroll view into a NestedScrollView and setting recyclerView.setNestedScrollingEnabled(false)
Has the highest performance and No need to override the layout manager.
I think you just need to wrap recyclerView so that other views can be visible. Just use this library so that you can adjust recycler view height coz linearLayoutManager as per now matches height to match parent.
https://github.com/serso/android-linear-layout-manager
it not as simple as you think. when you use tow scrollble element inside each other you are in hot water! you should calculate the Recycler item height and then find the whole recycler height.
look at below link, I explain completely this problem.
Use RecyclerView indie ScrollView with flexible recycler item height
I hope it help you

Categories

Resources