how to scroll recyclerview scroll the object outside recyclerview - android

I want to know is it possible to scroll recyclerview and scroll other object without using nested scroll or scrollview?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:gravity="center"
android:text="Text or other oject will list here"
android:id="#+id/info"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/business_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

<android.support.v4.widget.NestedScrollView
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">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:gravity="center"
android:text="Text or other oject will list here"
android:id="#+id/info"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/business_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Note: set recyclerView.setNestedScrollingEnabled(false); programmatically

Related

Android: RecyclerView layout problem when list goes off the screen

I have an activity where a test (questions with their corresponding possible answers on each fragment) is displayed.
The question is displayed and immediately below the possible answers are displayed with a RecyclerView.
If the question is short and the answers fit on the screen no problem is found, but the problem appears as soon as the question is longer and the RecyclerViews answers goes off the screen.
The issue apparently is RecyclerView's height is not properly calculated and it takes as its height the remaining space between the question bottom and the screen bottom, so if you scroll down you get a cut RecyclerView and only scrolling again inside of it fixes partially the problem.
This is my layout where you can see the RecyclerView:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
</data>
<RelativeLayout
android:id="#+id/llTestMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:background="#ffffff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:id="#+id/llBody"
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dip"
android:baselineAligned="false">
<LinearLayout
android:id="#+id/llTestHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal"
android:layout_gravity="bottom">
<TextView
android:id="#+id/tvQuestionNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:textColor="#4572ab"
android:textStyle="bold"
android:textSize="20sp"
android:textIsSelectable="false" />
<LinearLayout
android:id="#+id/llZoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:visibility="gone"
android:orientation="horizontal"
android:layout_gravity="end">
<TextView
android:id="#+id/tvZoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:textIsSelectable="false" />
</LinearLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:id="#+id/cbAndImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="#+id/llTvQuestion"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top|start"
android:orientation="horizontal">
<WebView
android:id="#+id/webViewQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:alwaysDrawnWithCache="false" />
</LinearLayout>
<LinearLayout
android:id="#+id/llTvImgInstructions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:paddingBottom="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/tvImgInstructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="false" />
</LinearLayout>
<LinearLayout
android:id="#+id/cbLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
android:scrollbars="none"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:id="#+id/rv" />
</LinearLayout>
<LinearLayout
android:id="#+id/llExplanations"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="20dp"
android:gravity="center"
android:orientation="vertical">
<WebView
android:id="#+id/webViewExplanations"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="70dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/llVerticalPager"
android:layout_weight="20"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="#ffffff"/>
</LinearLayout>
<include
android:id="#+id/llFetchingdata"
layout="#layout/testme_fetchingdata" />
</RelativeLayout>
</layout>
And this is how I set the RecyclerView in code:
private void createRecyclerView_TestMode(int pageNumber, TestDTO test)
{
LinearLayoutManager llm = new LinearLayoutManager(context,
LinearLayoutManager.VERTICAL, false);
RecyclerView rv = tBinding.rv;
rv.setLayoutManager(llm);
RVAdapter_Test_QuestionAnswers adapter =
new RVAdapter_Test_QuestionAnswers(pageNumber, test, tBinding, Enum.CallingActivity.Test);
rv.setAdapter(adapter);
}

RecyclerView scrolling very slow with NestedScrollView

I have a RecyclerView with a NestedScrollView and the recycler view scrolling is very very slow. Why is this happening, and how can I fix this?
After googleing and searching in Stack Overflow, i got this solution:
mMyRecyclerView.setNestedScrollingEnabled(false);
But it does not improve the scroll speed in my case, please help.
This is my xml code
<FrameLayout 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"
tools:context="fragment.HomeFrg">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/ns1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/card_background_new_design"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardElevation="5dp"
>
<LinearLayout
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="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/bestdeal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="5dp"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:text="DEALS"
android:visibility="gone"
android:textColor="#color/colorPrimary"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/viewall"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="end"
android:padding="5dp"
android:text="View All"
android:textColor="#color/colorPrimary"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_page2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
android:clipToPadding="false"
android:layout_marginBottom="5dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/activity_main_webview"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="150dp" />
<TextView
android:id="#+id/homefrgMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/nonetwork"
android:textSize="30sp"
android:visibility="visible"
android:textStyle="normal|bold" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="42dp"
android:layout_gravity="center"
android:layout_height="42dp"
android:visibility="visible"
android:id="#+id/progressBar_home_frg" />
</FrameLayout>
</FrameLayout>
This is my app on google play store, for your reference.
try to use this when you call your Linear layout manager
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false){
#Override
public boolean canScrollVertically() {
return false;
}
});
I am not sure but try RecyclerView height match_parent to wrap_content

Scrolling issue with RecyclerView in CoordinatorLayout

I have issue with scrolling in my code .. here is my xml :-
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#color/colorThemeDark"
android:fitsSystemWindows="true"
android:stateListAnimator="#drawable/appbar_always_elevated"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:collapsedTitleGravity="left"
app:contentScrim="#color/colorThemeDark"
app:expandedTitleGravity="center|bottom"
app:expandedTitleTextAppearance="#style/ExpandedAppBar"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circleView"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"
android:src="#drawable/main_logo"
app:layout_collapseMode="none" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#323642"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:id="#+id/firstText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="What you learn today?"
android:textColor="#color/colorWhite"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/catBoxes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstText"
android:layout_marginTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
<RelativeLayout
android:id="#+id/secondText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/catBoxes"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recommended for you"
android:textColor="#color/colorWhite"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/catMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/secondText"
android:layout_marginTop="5dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" </android.support.v7.widget.RecyclerView>
</RelativeLayout></android.support.design.widget.CoordinatorLayout>
I have two different recyclerView in single Activity.as in my code , i take root element as CoordinatorLayout. i add two RecyclerView in my code.when i scroll my recyclerview it scroll only first recyclerView and second RecyclerView scroll below first recyclerview. but i want to both recyclerView scroll at same time when i scroll up my screen.
Gif with my problem. Green boxes scrolled but i want to stop this green boxes scrolling
When you have two recycler view in a view and you want them to use all the space, you need to use NestedScrollView.
Your code will be the following:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#323642"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:id="#+id/firstText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="What you learn today?"
android:textColor="#color/colorWhite"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/catBoxes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstText"
android:layout_marginTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
<RelativeLayout
android:id="#+id/secondText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/catBoxes"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recommended for you"
android:textColor="#color/colorWhite"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/catMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/secondText"
android:layout_marginTop="5dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
And in your code, use this in both recycler view:
LayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setAutoMeasureEnabled(true);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setNestedScrollingEnabled(false);
More info in smbd uknow`s answer here

How to use swipe refresh with recyclerivew

I have use swipe resfresh with recyclerivew. but I see one problem. I can't scroll my recyclerivew up. I can scroll recyclerview down normally but every time I try to scroll up it will not scroll it up it is work the function swift refresh how ever I am not scrol up to the top yet.
Here is my xml
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginBottom="-5dp"
android:id="#+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/buslayout"
android:focusableInTouchMode="true"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:gravity="center"
android:text="Loading..."
android:id="#+id/info"
android:visibility="visible"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/business_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Try this:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginBottom="-5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:gravity="center"
android:text="Loading..."
android:id="#+id/info"
android:visibility="visible"/>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/swiperefresh"
android:focusableInTouchMode="true"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/business_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>

Android SwipeToRefresh - Confilct with RecyclerView when swiping down

So I have a fragment with 2 RecyclerView lists. I want to swipe fragment to refresh those lists but when I scroll one of those lists to see hidden elements SwipeToRefresh refreshes those lists. How to prevent it from that?
Here is my XML layout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_fragment">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/main_fragment_swipe_to_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_fragment_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#color/primary_dark"
android:text="Najpopularniejsze przepisy" />
<android.support.v7.widget.RecyclerView
android:id="#+id/top_recipes_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#color/primary_dark"
android:text="Najnowsze przepisy" />
<android.support.v7.widget.RecyclerView
android:id="#+id/latest_recipes_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
Any ideas?
You can consume the swipe down event in RecycleView when it can scroll up.
Just custom the RecycleView and intercept the event when you need.

Categories

Resources