I hava a layout below:
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</android.support.v7.widget.RecyclerView>
the recyclerView using LinearLayoutManager, a item of recyclerView is another recyclerView which using GridLayoutManager, set the gridLayoutRecyclerView's height, but the gridLayoutRecyclerView can not scroll inner
try this code
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
and also refer about this http://developer.android.com/training/material/lists-cards.html
After checking implementation, the reason appears to be the following. If RecyclerView gets put into a ScrollView, then during measure step its height is unspecified (because ScrollView allows any height) and gets equal to minimum height (as per implementation) which is apparently zero.
You have couple of options for fixing this:
Set a certain height to RecyclerView
Set ScrollView.fillViewport to true
Or keep RecyclerView outside of ScrollView.
If RecyclerView height is not limited - which is the case when it's put into ScrollView - then all Adapter's views have enough place vertically and get created all at once.
This is my out recyclerView's layout
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</android.support.v7.widget.RecyclerView>
then, a item of out recyclerView have another RecyclerView's which using GridLayoutManager, this is the code of the item below:
<android.support.v7.widget.RecyclerView
android:id="#+id/seatRecyclerView"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
the seatRecyclerView can't not to scroll
Related
I have a tags_frame in the FoodCardFragment (whose layout can be found here) that is used for displaying a RecyclerView in the TagsFragment. The layout of TagsFragment is simply:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start" />
The RecyclerView uses either StaggeredGridLayoutManager or LinearLayoutManager. However, as you can see from the middle of my cardview, this RecyclerView (composed of round-corner rectangles) uses StaggeredGridLayoutManager and it is centered. And actually in another activity I used LinearLayoutManager it is also centered.
How can I align it to the left (start) of the card?
You can try this in your fragment_tags.xml:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recycler_view"
android:layout_width="wrap_parent"
android:layout_height="match_parent"
android:layout_gravity="start" />
Use wrap_content for layout_width.
This happens because you are constraint your FrameLayout to parent on both sides and set width as match_parent. You have more options, One is to set gravity start to your framelayout or set width of the framelayout as wrap_content and constraint only to start.
I'm trying to implement nested RecyclerView. I did that but parent RecyclerView scroll was not smooth on scroll. I did alot of optimization, but still didn't manage to be successful with scroll till I though of putting parent recyclerview inside NestedScrollView. Scroll is flawless now, but I've a problem.
If I scroll (even tiny bit) my inner RecyclerView (horizontal), I immediately get back to the start [of vertical recyclerview - parent].
This happens one time. Why is that and is it possible to fix it?
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:id="#+id/parent_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
As far as I have understood your problem, you parent RecyclerView gets updated and scrolls to position 0 when the inner horizontal RecyclerView items get updated. You have also stated that the horizontal RecyclerView stays in the same place update the items are updated. In this case, you need to save the state of the parent RecyclerView and then put it back where it was after the items in your horizontal RecyclerView get updated.
// Save state
private Parcelable recyclerViewState;
recyclerViewState = parentRecyclerView.getLayoutManager().onSaveInstanceState();
// Restore state
parentRecyclerView.getLayoutManager().onRestoreInstanceState(recyclerViewState);
Save the state before you call the API for updating the data in your horizontal RecyclerView and then restore the position of the parent RecyclerView when the update finishes.
I got a solution.
Basically, what I did was wrap recycler view inside of relative layout and set android:descendantFocusability="blocksDescendants" and now it works good.
<android.support.v4.widget.NestedScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
<android.support.v7.widget.RecyclerView
android:id="#+id/parent_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
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 .
I have the following layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="#+id/searchView"
android:clipChildren="false"
android:clipToPadding="false"
android:scrollbars="vertical"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
which is a simple RecyclerView below a SearchView. I want the RecyclerView's views to scroll behind the SearchView, so clipChildren and clipToPadding are set to false.
My problem is that RecyclerView is (rightly) recycling its adapter's views when they are still visible, just because they are out of the RecyclerView's area. Is there a way to add an extra space to the RecyclerView within which views are not recycled?
EDIT, a gif showing the problem:
This method should help you setItemViewCacheSize(int size). It sets the number of offscreen views to retain before adding them to the potentially shared recycled view pool. More about it you can find here.
When I have my RecyclerView height as wrap_content, as below
<android.support.v7.widget.RecyclerView
android:id="#+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
The result as below.
The is because the resize happens before the animation.
It is described more clearly in
https://medium.com/#elye.project/recyclerview-supported-wrap-content-not-quite-f04a942ce624#.n7xivnrdr
Is there a way to force it to animate first then only resize?