NestedScrollview inside a Recycler view not scrolling - android

I am creating an Android program. In this program, I have a ScrollView inside of which there is a RecyclerView. I am adding data in this RecyclerView via a RecyclerViewAdapter.
For each item of the RecyclerView, there is a NestedScrollview having a single LinearLayout of vertical orientation. I am dynamically adding ImageView in this LinearLayout.
The problem is that the images are not scrolling. In very rare scenarios (by tapping so many times on screen), it got scrolled for once.
Could anybody help me on this?
Here is the code -
Parent Recycler View :-
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/id_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#color/gray3"
android:dividerHeight="5sp"
android:paddingLeft="2sp"
android:paddingTop="5sp"
android:paddingRight="2sp"/>
<com.app.sh.widget.WrappedGridView
android:id="#+id/gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/White"
android:numColumns="2">
</com.app.socialhand.widget.WrappedGridView>
</LinearLayout>
</ScrollView>
And the Item of the Recycler View :-
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/vScrollView"
android:layout_below="#id/iv_up"
android:layout_above="#+id/iv_down"
android:isScrollContainer="true"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/ll_123"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
I am dynamically adding the ImageViews in ll_123.

Try to use NestedScrollView instead of ScrollView or remove it. RecyclerView has own scrollview which will conflict with ScrollView.

You can try a structure like:
<ScrollView>
<NestedScrollView>
<LinearLayout>
<RecyclerView/>
</LinearLayout>
</NestedScrollView>
</ScrollView>
And ListItem layout should contain:
<NestedScrollView>
<LinearLayout/>
</NestedScrollView>
Check if this works correctly...

I got simmilar problem and this helped me:
<ScrollView
android:id="#+id/messages_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/send_panel"
android:fillViewport="true"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/messages"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:animateLayoutChanges="true"
android:gravity="center_horizontal|bottom"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
</ScrollView>

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<-only one layout in nestade layout->
<LinearLayout
android:id="#+id/activity_edit_existing_location"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/rcl"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<-put here yr second layout code->
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Related

How can I add two Scroll views in a xml layout such that each scrollview take half of the height of the layout?

How do I add two ScrollViews in an android XML-layout such that each scroll view takes half of the height of the layout?
You can use LinearLayout as rootview then add two ScrollView as child and assign android:layout_weight="1" to both ScrollView
Note : if you want your view scroll horizontally then use HorizontalScrollView
SAMPLE CODE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/black"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--add viw here-->
</LinearLayout>
</ScrollView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/holo_red_dark"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--add viw here-->
</LinearLayout>
</ScrollView>
</LinearLayout>
OUTPUT
There is a multiple way to do this. I am suggesting you one simple way.
try to add weightsum =2 inside parent layout. And devide layout with 1 like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_rel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2.0" >
<RelativeLayout
android:id="#+id/child_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="#0000FF" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/child_two"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="#00FF00" >
</RelativeLayout>
</LinearLayout>

How can i add double ScrollView in XML?

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 RecyclerView in scrollview

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

NestedScrollView could not scroll with match_parent height child

I implement NonSwipeableViewPager with a fragment has NestedScrollView like this, what I expect is that the scrollview can scroll up and show 2 textviews:
<?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"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/header" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_up" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 2" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
But it could not scroll, I tried many ways but still did not get any solution
<?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"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
This linearlayout should have android:layout_height="wrap_content".
Reason for that is that if the scrollview's child is the same size as the scrollview itself (both match_parent for height) it means that there is nothing to scroll through, since they are of same size and the scrollview will only be as high as the screen.
If the linearlayout has a height of wrap_content then the height is not related to the height of the screen and the scrollview will be able to scroll through it.
Just remember that a scrollview can only have 1 direct child, and that child needs android:layout_height="wrap_content"
In my case app:layout_behavior="#string/appbar_scrolling_view_behavior" this is working only if some one face problem will be try it and may be solve your problem too. you should add also android:fillViewport="true" but without this my code working.
<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:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/subscription_background"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
For me it worked when i added "android:layout_marginBottom="100dp"" for last child in androidx.core.widget.NestedScrollView
if you have used netedscrollview as follow you have to use
android:scrollbars="vertical"
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/toolbar_updateUserDetails"
app:layout_constraintBottom_toBottomOf="parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical"
>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
You have to calculate your other child because last child binding on nestedScrollView. You add margin like child height. It is working.

cardview is not wrapping the content inside swipeview

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>

Categories

Resources