RecyclerView scrolling very slow with NestedScrollView - android

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

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);
}

linearlayout is not getting displayed below recyclerview

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
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>
You haven't added weightSum and orientation values ​​for LinearLayout.
Source
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);
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>

The view is not a child of CoordinatorLayout

I am getting java.lang.RuntimeException: Unable to start activity java.lang.IllegalArgumentException: The view is not a child of CoordinatorLayout.working with bottom sheet, I have tried lot of combination but still i am not getting solution. please tell me any solution.Thank you in advance.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/beyprod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/toolbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
<!-- <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/bottom_sheet_behavior" />
</LinearLayout>-->
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/bottom_sheet_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".retailerModule.cart.activity.AddressListActivity">
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relaLaySearch"
android:layout_gravity="center|top"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/confirmBtn"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<TextView
android:id="#+id/addNewAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="right"
android:layout_marginTop="15dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="40dp"
android:background="#color/green"
android:gravity="center"
android:padding="10dp"
android:text="New Address"
android:textColor="#color/colorWhite" />
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="#+id/continueBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="right"
android:background="#color/color_blue"
android:gravity="center"
android:text="SAVE"
android:textColor="#color/colorWhite"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
When i tried to run this line getting exception
NestedScrollView mBehavior = BottomSheetBehavior.from(bottom_sheet);
It tells you that you can only put a BottomSheetBehavior into a CoordinatorLayout.
So make CoordinatorLayout as your root layout and place it directly here (not in some nested views)

NestedScrollView getting stuck with recyclerview

I am using NestedScrollView and I have 3 recyclerviews . I am parsing json and set data in recyclerview, now the issue is that in my last recyclerview I have set pagination feature, so until data is not fetched for that recyclerview, my whole screen got stuck and freeze. I tried a different solution for that. but it's not working and I found no change in result. can anyone help me with that?
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
android:background="#f0f0f0"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<include layout="#layout/reseller_home_title" />
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="#+id/bodyScroller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:fillViewport="true"
android:background="#f0f0f0"
android:scrollbars="vertical">
<LinearLayout
android:id="#+id/llFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
<RelativeLayout
android:id="#+id/temp_orange_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorAccent"
/>
<com.youth.banner.Banner
android:id="#+id/banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/_10sdp"
android:layout_marginLeft="#dimen/_10sdp"
android:layout_marginTop="#dimen/_10sdp"
app:indicator_drawable_selected="#drawable/library_module_bg_style_main_radious"
app:indicator_height="5dp"
app:indicator_width="5dp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewCategoryData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:isScrollContainer="false"
android:background="#color/white"
android:nestedScrollingEnabled="false"
android:paddingTop="#dimen/_10sdp" />
<LinearLayout
android:id="#+id/resellerPromotionBannerLayout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:weightSum="2"
android:orientation="horizontal"
android:background="#f0f0f0"
android:layout_marginTop="#dimen/_10sdp"
>
<ImageView
android:id="#+id/iv_top_left_pro"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<ImageView
android:id="#+id/iv_top_right_pro"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewGroupData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:isScrollContainer="false"
android:nestedScrollingEnabled="false"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewGroupProductData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0f0f0"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:descendantFocusability="blocksDescendants"
android:isScrollContainer="false"
android:nestedScrollingEnabled="false"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f0f0"
android:layout_marginTop="#dimen/_5sdp"
>
<TextView
android:id="#+id/tv_size_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="THEY'RE ALL SELLING THIS"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textColor="#color/colorBlack"
android:textSize="16dp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewHpEntryData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:isScrollContainer="false"
android:background="#f0f0f0"
android:layout_marginTop="#dimen/_5sdp"
android:nestedScrollingEnabled="false"
>
</android.support.v7.widget.RecyclerView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/_15sdp"
android:background="#f0f0f0"
android:layout_marginTop="#dimen/_5sdp"
>
<ProgressBar
android:id="#+id/reseller_promotion_view_progress"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="false"
android:max="100"
android:progress="20"
android:maxHeight="3dip"
android:minHeight="3dip"
android:progressDrawable="#drawable/resellerpromotion_progress" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewProductData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f0f0"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:descendantFocusability="blocksDescendants"
android:isScrollContainer="false"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp">
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<include layout="#layout/error_layout"
/>
</android.support.design.widget.CoordinatorLayout>
run below code for each of your RecyclerView within your NestedScrollView
ViewCompat.setNestedScrollingEnabled(recyclerView, false);
Try this code, it works well,
rvCompanies.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rvCompanies.setLayoutManager(layoutManager);
rvCompanies.setNestedScrollingEnabled(false); // important

How to make two cardview scrolling horizontally?

I have two cardview which have different childview and i want them to display at the bottom of my screen and want them horizontally scrolling, i have read other docs. but none of them fits for me. i have tried Horizontalscrollview but it didn't help.
Thanks in advance.
<android.support.v7.widget.CardView
android:id="#+id/cardViewDemo1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:elevation="5dp"
app:cardBackgroundColor="#e4a455"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:weightSum="1">
<FrameLayout
android:id="#+id/frameDemoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="3dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:scaleType="fitXY"
android:src="#drawable/demo_one" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/frame" />
</FrameLayout>
<android.support.v7.widget.CardView
android:id="#+id/cardViewDemo3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_weight=".8"
app:cardBackgroundColor="#e9e6e3"
app:cardCornerRadius="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="DEMOVIDEOONE"
android:textColor="#c9750f"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardViewDemo2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:elevation="5dp"
app:cardBackgroundColor="#e4a455"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:weightSum="1">
<FrameLayout
android:layout_weight=".2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/demo_one" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/frame" />
</FrameLayout>
<android.support.v7.widget.CardView
app:cardBackgroundColor="#e1b784"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_weight=".8"
app:cardCornerRadius="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="DEMOVIDEOONE"
android:textColor="#fff"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v7.widget.CardView>
Use NestedScrollView as a container of two CardView.
Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="#+id/card_view_one"
android:layout_width="300dp"
android:layout_height="200dp">
<!-- Content -->
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/card_view_two"
android:layout_width="300dp"
android:layout_height="200dp">
<!-- Content -->
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>

Categories

Resources