When i place HIChartView(From HighCharts library) inside NestedScrollView or RecyclerView and try to scroll up the page by touching on the chartView, the recyclerview scroll movement is very laggy.
This is happening only when i touch the chartview and try to scroll the page up. But the recyclerview scroll is smooth when i touch outside of the chartview and move the page up.
When the tooltip is visible on chart and user tries to scroll, then the lag is more evident and annoying.
HIChartView extends RelativeLayout
Tried following two ways, both did not work
1)In nested scroll view
<androidx.core.widget.NestedScrollView
android:id="#+id/nsv_view_trend"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#color/background_interface_secondary"
app:layout_constraintBottom_toTopOf="#id/cv_footer"
app:layout_constraintTop_toBottomOf="#id/cl_header">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.highsoft.highcharts.core.HIChartView
android:id="#+id/trend_graph"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="#dimen/space_20dp"
app:layout_constraintTop_toBottomOf="#id/chart_label"
/>
<FooterView
android:id="#+id/privacy_policy_footer_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="#dimen/space_16dp"
android:layout_marginTop="#dimen/space_24dp"
android:layout_marginBottom="#dimen/space_16dp"
android:visibility="gone"
tools:visibility="visible" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
2)As an item in recyclerView
Any ideas on how to solve this issue ?
Related
The problem is that the ScrollView scrolls till it completes all the content of my layout, then it keeps scrolling and shows empty layout. It keeps scrolling for a long empty length. I guess the problem is in using the RecyclerView inside a ScrollView, and I just know that this will result in a poor UI experience, but the point now is to make it work
Here is the component tree of my layout
And here is the snippet of the xml code for the part of the ScrollView
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white_smoke"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout...>
<LinearLayout
android:id="#+id/frameLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/comments_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white_smoke" />
</LinearLayout>
</LinearLayout>
After trying a few solutions. Wrapping the RecyclerView in a RelativeLayout instead of LinearLayout has solved the problem for me. A final thing to not forget, do not use RecyclerView in a ScrollView as the RecyclerView will not recycle its views. You can do that if you are sure that there are no many items in the RecyclerView.
I am developing an app that uses a vertical bottom sheet. To be more specific, it is a LinearLayout with bottomSheetBehavior. This bottom sheet comprises two elements: a view pager that displays images and can be scrolled horizontally, and, below the view pager, a Recycler View whose elements can be scrolled vertically.
The good layout file looks like this:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/colorBackground"
android:orientation="vertical">
<!-- works with and without frame layout-->
<FrameLayout
android:id="#+id/play_queue_square_frame"
android:layout_width="match_parent"
android:layout_height="350dp">
<androidx.viewpager.widget.ViewPager
android:id="#+id/play_queue_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/play_queue_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
app:layoutManager="LinearLayoutManager"
android:background="?android:attr/colorBackground"
tools:listitem="#layout/item_view_song_debug" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
With the above layout everything is working as expected. In particular, the view pager scrolls in horizontal direction, the recycler view scrolls in vertical direction, and dragging either the view pager or the recycler view in horizontal direction closes the bottom sheet.
However, when replacing the view pager by androidx.viewpager2.widget.ViewPager2 yields odd behaviour. Scrolling the view pager in horizontal direction is still possible, but vertical scrolling does no longer work. Any swipes downward simply close the bottom sheet.
Using a NestedScrollView yields better results but still has erroneous behaviour.
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/colorBackground"
android:orientation="vertical">
<FrameLayout
android:id="#+id/play_queue_square_frame"
android:layout_width="match_parent"
android:layout_height="300dp">
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/play_queue_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/play_queue_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
app:layoutManager="LinearLayoutManager"
android:background="?android:attr/colorBackground"
tools:listitem="#layout/item_view_song_debug" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Scrolling in vertical direction is still possible, and also the horizontal scrolling for the view pager. However, dragging the view pager down does no longer close the bottom sheet, whereas a dragging the recycler view down does.
If I add the following code
viewPager.setUserInputEnabled(false)
the view pager does no longer allow horizontal scrolling (as expected). So my question is simply what I have to do in order to allow horizontal scrolling and make sure that a vertical swipe downwards (on the view pager) closes the bottom sheet.
I know that a somewhat similar question has already been asked (in this post)
but as there is no answer so far I take the liberty to ask this question. What confuses me most is that it is working with the old viewpager but not with viewpager2.
Any help is greatly appreciated!
I want to implement two RecyclerView with different layout in single activity. The above RecyclerView should scroll vertical and the one below should scroll horizontal. But when I run the app, only either one RecyclerView is displayed. If first view is displayed then it works properly and scrolls vertical, while second RecyclerView is missing. And if second one is displayed then it scrolls vertical when it should do horizontal scroll and the first RecyclerView is missing.
Here is what i want. Source: Github,CardView-Recyclerview-Picasso
Here is my layout
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackgroundLight"
android:smoothScrollbar="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/CategoriesRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/videoRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="130dp"
android:layout_below="#+id/CategoriesRecyclerView"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
You may directly use the 2 Recycler Views without NestedScrollView.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/CategoriesRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/videoRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="130dp"
android:layout_below="#+id/CategoriesRecyclerView"/>
</RelativeLayout>
And in your CategoriesRecyclerView whose height is wrap_content, use setAutoMeasureEnabled(true) on the Layout manager used for the recyler view.
If you want to scroll the horizontal scrollview full upside on page scroll then use scrollview otherwise you can do without scrollview. Also to achieve your layout just give the horizontal recyclerview fixed height and then you can see both recyclerview .
Im trying to rig a horizontally oriented RecyclerView with child items that contain a HorizontalScrollView. What I have configured right now is not allowing the nested HorizontalScrollView to scroll its content.
Heres an abbreviated version of my activity layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RecyclerView
android:id="#+id/home_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
And here's an abbreviated version of the item layout:
<android.support.v7.widget.CardView
android:id="#+id/main_card"
android:layout_width="335dp"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
</android.support.v7.widget.CardView
So Im trying to get the Text content inside the Horizontal ScrollView to be scrollable.
EDIT :
Below is a screenshot of the textview that will not scroll. As you can see, the text is cut off at the end of the view, and this is why Im looking to implement horizontal scrolling.
NOTE: I tried changing the LayoutManager associated with my RecyclerView to have vertical orientation, and horizontal scrolling works as expected. Knowing this, it seems that the RecyclerView is absorbing all scroll events and not allowing the nested HorizontalScrollView to do its thing
I have a RecyclerView as the bottom view, along with some other views on top:
I want to scroll the entire view (1), not just the RecyclerView (2).
I have managed to get it to work, but not flawlessly. XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
...
<View
style="#style/Divider"
android:layout_marginBottom="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewNote"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
Two problems:
Scrolling in the recyclerview isn't smooth, in the sense that when I lift up my finger, the scrolling stops. No accelerated scroll, or whatever you call it.
When I remove items from the recyclerview, its height remains the same. Meaning I have empty space where the images once was.
I have tried with your example
Scrolling in the recyclerview isn't smooth, in the sense that when I
lift up my finger, the scrolling stops. No accelerated scroll, or
whatever you call it.
Even I noticed that. I think there are some restrictions when you use nested scrolling as it has to handle both scrolls.
When I remove items from the recyclerview, its height remains the
same. Meaning I have empty space where the images once was.
The white space is because of the padding you have applied to the linear layout of recyclerview. Event though you remove all items from recyclerview the padding of parent linear layout remains same and so is the whitespace.
use nestedScrollView
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>