How to use two recyclerView in single activity? - android

I want to implement two RecyclerView with different layout in single activity. The above RecyclerView should scroll vertical and the one below should scroll horizontal. But when I run the app, only either one RecyclerView is displayed. If first view is displayed then it works properly and scrolls vertical, while second RecyclerView is missing. And if second one is displayed then it scrolls vertical when it should do horizontal scroll and the first RecyclerView is missing.
Here is what i want. Source: Github,CardView-Recyclerview-Picasso
Here is my layout
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackgroundLight"
android:smoothScrollbar="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/CategoriesRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/videoRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="130dp"
android:layout_below="#+id/CategoriesRecyclerView"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>

You may directly use the 2 Recycler Views without NestedScrollView.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/CategoriesRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/videoRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="130dp"
android:layout_below="#+id/CategoriesRecyclerView"/>
</RelativeLayout>
And in your CategoriesRecyclerView whose height is wrap_content, use setAutoMeasureEnabled(true) on the Layout manager used for the recyler view.

If you want to scroll the horizontal scrollview full upside on page scroll then use scrollview otherwise you can do without scrollview. Also to achieve your layout just give the horizontal recyclerview fixed height and then you can see both recyclerview .

Related

ScrollView is keeping scrolling although the layout is empty

The problem is that the ScrollView scrolls till it completes all the content of my layout, then it keeps scrolling and shows empty layout. It keeps scrolling for a long empty length. I guess the problem is in using the RecyclerView inside a ScrollView, and I just know that this will result in a poor UI experience, but the point now is to make it work
Here is the component tree of my layout
And here is the snippet of the xml code for the part of the ScrollView
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white_smoke"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout...>
<LinearLayout
android:id="#+id/frameLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/comments_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white_smoke" />
</LinearLayout>
</LinearLayout>
After trying a few solutions. Wrapping the RecyclerView in a RelativeLayout instead of LinearLayout has solved the problem for me. A final thing to not forget, do not use RecyclerView in a ScrollView as the RecyclerView will not recycle its views. You can do that if you are sure that there are no many items in the RecyclerView.

Multiple horizontal RecyclerView inside NestedScrollView steal focus

Actually I'm currently working for a AndroidTV app. I have multiple horizontal RecyclerView right to left inside a NestedScrollView like that image.
Problem is that when I scroll more towards left, then focus moves to different list or different view which is not good.
I don't want the focus to change. If the list reaches to the end, then focus should remain at same position.
I tried :
android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true" //in parent layout
But it didn't work..
Can anyone help me out ??
Not solved
Try changing your ScrollView to NestedScrollView. A reason behind this is
**NestedScrollView**
NestedScrollView is just like ScrollView, but it supports acting as
both a nested scrolling parent and child on both new and old versions
of Android. Nested scrolling is enabled by default.
**ScrollView**
Layout container for a view hierarchy that can be scrolled by the
user, allowing it to be larger than the physical display. A ScrollView
is a FrameLayout, meaning you should place one child in it containing
the entire contents to scroll; this child may itself be a layout
manager with a complex hierarchy of objects
This will help you to determine which layout is being focused.
You can use below structure for nested scroll
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:clickable="false"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll_search_all"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
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">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:nestedScrollingEnabled="false" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:nestedScrollingEnabled="false" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</FrameLayout>
I hope this will help!
Try using this one code in your recycleview section 2:
android:layoutDirection="rtl"

Horizontal RecyclerView with nested HorizontalScrollView

Im trying to rig a horizontally oriented RecyclerView with child items that contain a HorizontalScrollView. What I have configured right now is not allowing the nested HorizontalScrollView to scroll its content.
Heres an abbreviated version of my activity layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RecyclerView
android:id="#+id/home_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
And here's an abbreviated version of the item layout:
<android.support.v7.widget.CardView
android:id="#+id/main_card"
android:layout_width="335dp"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
</android.support.v7.widget.CardView
So Im trying to get the Text content inside the Horizontal ScrollView to be scrollable.
EDIT :
Below is a screenshot of the textview that will not scroll. As you can see, the text is cut off at the end of the view, and this is why Im looking to implement horizontal scrolling.
NOTE: I tried changing the LayoutManager associated with my RecyclerView to have vertical orientation, and horizontal scrolling works as expected. Knowing this, it seems that the RecyclerView is absorbing all scroll events and not allowing the nested HorizontalScrollView to do its thing

RecyclerView part of ScrollView

I have a RecyclerView as the bottom view, along with some other views on top:
I want to scroll the entire view (1), not just the RecyclerView (2).
I have managed to get it to work, but not flawlessly. XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
...
<View
style="#style/Divider"
android:layout_marginBottom="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewNote"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
Two problems:
Scrolling in the recyclerview isn't smooth, in the sense that when I lift up my finger, the scrolling stops. No accelerated scroll, or whatever you call it.
When I remove items from the recyclerview, its height remains the same. Meaning I have empty space where the images once was.
I have tried with your example
Scrolling in the recyclerview isn't smooth, in the sense that when I
lift up my finger, the scrolling stops. No accelerated scroll, or
whatever you call it.
Even I noticed that. I think there are some restrictions when you use nested scrolling as it has to handle both scrolls.
When I remove items from the recyclerview, its height remains the
same. Meaning I have empty space where the images once was.
The white space is because of the padding you have applied to the linear layout of recyclerview. Event though you remove all items from recyclerview the padding of parent linear layout remains same and so is the whitespace.
use nestedScrollView
<android.support.v4.widget.NestedScrollView
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.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>

can i create a nestedScroll Layout like this?

I think it can be achieved by NestedScrollingChild NestedScrollingParent.
But I can't really understand them.Who can help me out!
Product manager insists on the design.
The ScrollView contains a LinearLayout ,a "TabLayout" and a ViewPager.
The ViewPager contains 2 fragment contains RecyclerView or just only 2 RecyclerView.
When the ScrollView scroll to Bottom , the RecyclerView can scroll to Bottom.
When the RecyclerView scroll to Top , the ScrollView can scroll to Top.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="1000dp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="60dp"></TableLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v4.view.ViewPager>
</LinearLayout>
</ScrollView>
Just change your ScrollView to android.support.v4.widget.NestedScrollView
Post your xml if that doesn't work
ِYou can do that, but it's not good at all to use this type of layout
First you need add "wrap_content" abilty ViewPager and RecyclerView's
ViewPager and RecyclerView
Now you can use scrollview easily, put all item in it
If you want some effect or something when user scrolling or some item get visible in scrolling you can get position of item then make listener on
"OnScrollChangedListener" of scrollview

Categories

Resources