In my layout, ScrollView is the parent and it has Imageview (160dp height) and a Recyclerview as children. Scenario: there's the image and 10 String item list, visible listitems are 0,1,2,3,4. So Whenever there's a new listitem ,I will update the list and call scrollToPosition method(itemcount -1), but nothing happens. I already have setNestedScrollEnabled(false).
I tried scrollView.fullScroll(DOWN) method, scrollView.scrollTo(0, adapter.itemcount), using this it scrolls to last item of the old list, but not scrolled completely to show added new item. This is my layout
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null">
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="140dp" />
<View
android:id="#+id/grey_line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_grey"
android:visibility="gone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/comments_list"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
Please help, Thank you!
May be you are using
android:descendantFocusability="blocksDescendants"
inside your Layout.
If not then try to use
android:focusable="true"
android:focudeableInTouchMode="true"
inside your Recyclerview
Related
This question already has answers here:
RecyclerView inside ScrollView is not working
(26 answers)
Closed 2 years ago.
i have
MAIN VIEW
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
/>
</ScrollView>
On my template adapter, i have a another recycler adapter for child views
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="#+id/title_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:background="#color/GRAY"
android:text="TextView" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_for_specification_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:nestedScrollingEnabled="false"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
The code work, but when user scroll on android device, the parent scrollView does not allow me to scroll over the recycler view (1)
Use NestedScrollview instead of scrollview and use android:nestedScrollingEnabled="false" for recycler_products recyclerview not in both
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
/>
</androidx.core.widget.NestedScrollView>
If you are not able to scroll it is because of this line
android:nestedScrollingEnabled="false".
Change it to True, so you can enable the scrolling:
android:nestedScrollingEnabled="true".
In you code you have recylerview inside scroll view, this is wrong.
Option 1: If scroll view has not any other child view than remove it and just use recyclerview and also remove android:nestedScrollingEnabled="false
And your Main View code looks like this;
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Option 2: If scroll view has also other child including recyclerview than you should use nestedscrollview like below code:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">
<ImageView
android:id="#+id/sellerProduct"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:src="#drawable/iphone"
android:scaleType="fitXY"
android:contentDescription="#string/app_name" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:nestedScrollingEnabled="false
android:id="#+id/productList"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
In my android application, there is a slideshow at top of page and below it, there is a recycler view, my problem is how to add the slideshow above recycler view in a way that slideshow can be scrolled with recycler view. I tried adding a scroll view as a parent but it seems that recycler lost the recycling power.
<RelativeLayout
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:background="#ececec">
<android.support.v4.view.ViewPager
android:id="#+id/ChefFragmentViewPager"
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_alignParentTop="true" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/ChefFragmentViewPager"
android:background="#ececec"
android:scrollbars="none" />
</RelativeLayout>
Try using NestedScrollView instead of ScrollView and also set recyclerView.setNestedScrollingEnabled(false); programmatically.
Try this code and let me know if it helped you or not:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
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:background="#ececec">
<android.support.v4.view.ViewPager
android:id="#+id/ChefFragmentViewPager"
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_alignParentTop="true" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/ChefFragmentViewPager"
android:background="#ececec"
android:scrollbars="none" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
I am currently trying to add a double ScrollView inside my XML.
I am using two different views in my layout - a list and categories.
When a user clicks on a category - the list of videos will become visible and the categories will become invisible.
Currently, the category buttons are scroll-able and when I click a category button, the list of videos does become visible. However, the issue is that the list of videos do not scroll.
Here is my layout code:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/tools"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--this is parent layout where I call ListView-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/parent01"
android:descendantFocusability="beforeDescendants"
android:fitsSystemWindows="true"
android:focusableInTouchMode="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:orientation="vertical"
android:weightSum="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:divider="#android:color/transparent"
android:dividerHeight="1dp"></ListView>
<ProgressBar
android:id="#+id/nextProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:visibility="gone"
style="#android:style/Widget.DeviceDefault.Light.ProgressBar.Small"/>
</RelativeLayout>
</LinearLayout>
<!--This is the categories layout-->
<ScrollView
android:layout_width="wrap_content"
android:orientation="vertical"
android:id="#+id/ll_buttons"
android:layout_marginTop="60dp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="200dp">
<Button
android:layout_weight="0.5"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/rec_img"/>
<Button
android:layout_weight="0.5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/rec_img"
android:id="#+id/button2"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="200dp">
<Button
android:layout_weight="0.5"
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/rec_img"/>
<Button
android:layout_weight="0.5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/rec_img"
android:id="#+id/button4"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
for nested scrolling better to use NestedScrollView
NestedScrollView as the name suggests is used when there is a need for a scrolling view inside another scrolling view.
ScrollView vs NestedScrollView
another thing use RecyclerView insted of Listview
RecyclerView vs. ListView
sample layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
// add here all your controlls
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
and dont forgot to set setNestedScrollingEnabled() property in RecyclerView like below code
If this property is set to true the view will be permitted to initiate nested scrolling operations with a compatible parent view in the current hierarchy. If this view does not implement nested scrolling this will have no effect. Disabling nested scrolling while a nested scroll is in progress has the effect of stopping the nested scroll.
mRecyclerView.setNestedScrollingEnabled(false);
use nested scroll views
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.widget.NestedScrollView>
how to scroll all above RecyclerView in scrollview
I have to implement RecyclerView in scrollview show as below code, but not scroll RecyclerView.
please give answer
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/horizontalScrollView"
android:layout_marginTop="10dp">
<RelativeLayout...
<android.support.v7.widget.RecyclerView
android:id="#+id/rvpouch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:layout_below="#+id/textView3">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</ScrollView>
Don't use RecyclerView inside ScrollView. Use NestedScrollView instead of ScrollView.
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.
For Example:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_three"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Use attribute android:nestedScrollingEnabled="false" for smooth scrolling.
Use NestedScrollView instead of scroll view and set
recyclerView.setNestedScrollingEnabled(false);
Following code snippet will help you to implement scrolling using ScrollView of RecyclerView
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarSize="3dp"
android:scrollbarThumbVertical="#drawable/scrollbar_black">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/rlFiltersSearchEvent"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#drawable/action_bar_gradient">
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvListOfEventsMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/fab_margin"
android:layout_below="#+id/rlFiltersSearchEvent"
android:nestedScrollingEnabled="false"
android:scrollbars="none" />
</RelativeLayout>
</ScrollView>
Hope it helps
I Want to display an listview inside an Cardview.
This is the Code I used :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/list_layout_with_fab_list_view_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp">
<ListView
android:id="#+id/list_layout_with_fab_list_view"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:divider="#null"
android:fastScrollEnabled="true"
android:listSelector="#android:color/transparent"
android:outlineProvider="none" />
</android.support.v7.widget.CardView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
If i remove the SwipeView the CardView is wrapping the content. but i need both swipeview as well as CardView.
Is there anything i have done wrong??
You want to wrap a content inside cardview make sure that your card view height should set to height which is able to handle the content inside just give height in numbers and check weather it handles your content or not.Use this code in your layout and check if it works or not and in #dimes/fab_margin you can set the height for your cardview.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="#dimen/fab_margin"
app:cardCornerRadius="2dp"
app:cardElevation="6dp"
android:layout_alignParentBottom="true"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView">
</ListView>
</android.support.v7.widget.CardView>
</RelativeLayout>