I have recyclerview in a bottomsheet, and that works fine. When I introduce a swiperefreshlayout around the recycler view, it doesn't allow me to scroll up, it only collapses the bottomsheet. I would like it scroll the recycler view, reach the top and then trigger a refresh. If I need to, I'm okay with getting rid of the drag to collapse behavior on the bottomsheet.
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/background_light"
app:behavior_peekHeight="?actionBarSize"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" >
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:visibleGone="#{ model.locPerms }"
app:onRefreshListener="#{ () -> model.refreshPois() }"
app:refreshing="#{ model.refreshing }">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list_pois"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
tools:listitem="#layout/poi_item"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Try disable nested scrolling on the recylerView
list_poits.isNestedScrollingEnabled = false
Related
I have an AppBarLayout that expands if the user scrolls down the list a little bit and it comes back up after 2 seconds if the user is not scrolling anymore. However, the annoying thing is that AppBarLayout is also scrolling the RecyclerView for the amount of AppBarLayout's height. That way it keeps the list at the same position where the user stopped in the list so the list doesn't move, however, the viewport does and I would like to disable that if possible.
The only way it kind of works is when I placed ViewPager (in it is later on Fragment that contains RecyclerView) above the AppBarLayout and removed app:layout_behavior.
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/divider_logo">
<androidx.viewpager.widget.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
app:elevation="0dp"
app:layout_behavior="com.my.app.sava.main.AppBarLayoutBehavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<View
android:id="#+id/tv_location_bg"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/colorPrimaryLight"
app:layout_constraintBottom_toBottomOf="#id/tv_location"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/tv_location" />
.
.
.
However there is a delay when wanting to scroll then because AppBarLayout is scrolled first without the list moving, then the RecyclerView is starting to scroll.
I have a row that has a recyclerview inside another recyclerview, like this image
I need the inner recyclerview to be able to scroll it, I have tried this (this is inside a ConstrainLayout)
<androidx.core.widget.NestedScrollView
android:id="#+id/nested_scroll"
android:layout_width="match_parent"
android:layout_height="150dp"
android:fillViewport="true"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_order_items"
android:layout_width="match_parent"
android:layout_height="0dp" />
</androidx.core.widget.NestedScrollView>
And
rv_order_items.isNestedScrollingEnabled = true
But I cant scroll inside the inner recyclerview, any suggestion?
Please add whole code of your layout in this post so I will get idea about constraintlayout.
Otherwise this is solution if you want full screen to scroll...
Please set android:layout_height="match_parent" of NestedScrollView
<androidx.core.widget.NestedScrollView
android:id="#+id/nested_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
Basically I have a fragment with a specific layout, which has CoordinatorLayout as its parent and a static fragment with BottomSheetBehaviour(also some other views that are not related to the question)
`
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/main_activity_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
Some other views....
<fragment
android:id="#+id/home_apps_widget"
android:name="apps.calo.justLauncher.fragments.HomeAppsWidget"
android:layout_width="0dp"
android:layout_height="57dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<fragment
android:id="#+id/bottom_sheet_container"
android:name="apps.calo.justLauncher.fragments.AppDrawerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="#layout/app_drawer_fragament"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
tools:layout="#layout/app_drawer_fragament" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
`
Inside the static fragment, I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/app_drawer_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/app_drawer_background">
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/app_drawer_indicator"
android:visibility="invisible"
android:layout_below="#id/app_search_widget"
android:layout_marginTop="8dp"
android:layout_marginBottom="5dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/app_list_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="4"
android:clipToPadding="false"
app:spanCount="4"
tools:listitem="#layout/app_item"
android:layout_above="#id/app_drawer_indicator"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
android:orientation="vertical"
android:layout_below="#id/app_search_widget"
android:layout_marginTop="8dp"
android:layout_marginBottom="5dp" />
<apps.calo.justLauncher.view.Pager2Indicator
android:id="#+id/app_drawer_indicator"
android:layout_width="wrap_content"
android:layout_height="11dp"
android:layout_alignParentBottom="true"
app:piv_radius="3dp"
app:selectedColorCustom="page_indicator_selected"
app:tabIndicatorHeight="3dp"
app:unselectedColorCustom="page_indicator_unselected" />
</RelativeLayout>
</layout>
With the following setup, you can only have one active (recyclerview or viewpager2), which can be altered with SharedPreferences.
My goal is, when you scroll the RecyclerView to the top, your next scroll would be taken over by the bottom sheet(if you try to scroll recyclerview to the top again) and the touch would move the Y position of the bottom sheet.
I want the same thing with the viewpager but here you don't have to scroll to the top because it is not scrollable, so basically if you scroll towards down, the bottom sheet would take over the touch.
With the current setup both RecyclerView and ViewPager "swallow" the touch and you are not able to control the bottom sheet from them. You can still colapse the bottom sheet if you pull it down by touching on the view that is above recyclerview/viewpager.
My question is: How can I delegate the touch from the recyclerview/viewpager to the BottomSheet in order to control Y position of BottomSheet.
The interesting thing is, when I change the ViewPager2 to ViewPager, I have the desired effect with the RecyclerView, but not with ViewPager.
Thank you!
I figured a way to do this. I attached a touch listener to RecyclerView and ViewPager. Created an interface that connects two fragments(fragment that contains the bottom sheet and the bottom sheet fragment). In the case of RecyclerView being visible, I would check if the RecyclerView is scrolled to the top. If it is, I would check if the user is swiping towards down with the touch listener. If he is, I forward the touch to Fragment which contains the BottomSheet and forward the touch event with the root view of BottomSheet, and run this method:
fun forwardTouchToBottomSheet(event: MotionEvent, view: View) {
bottomSheetBehavior.onTouchEvent(cor, view, event)
}
In the case of ViewPager, the touch listener would not work on ViewPager2 view(because views would take over the touch I guess) so I just put the listener on views inside the ViewPager and run the previous method through another interface.
Basically i have implemented recyclerview in nested scroll view which contains the arc seek bar in each item of recyclerview. So when i move seekbar recyclerview is also scrolling.
I tried using nestedscrollview and focusableInTouchMode option but did not worked.
device_list.apply {
device_list.layoutManager = GridLayoutManager(this#RoomActivity, 2)
device_list.adapter = DeviceAdapter()
}
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
android:background="#color/colorWhite">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/device_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginSemiGlobal"
android:layout_marginBottom="#dimen/marginSemiGlobal"
android:overScrollMode="never"
android:nestedScrollingEnabled="false"
android:scrollbars="none" />
</androidx.core.widget.NestedScrollView>
<com.marcinmoskala.arcseekbar.ArcSeekBar
app:roundEdges="true"
android:layout_width="match_parent"
android:layout_below="#+id/top_layout"
app:progressBackgroundColor="#color/colorProgressBackground"
app:progressBackgroundWidth="8dp"
app:progressColor="#color/colorProgress"
android:id="#+id/dimmer"
app:progressWidth="8dp"
android:layout_height="100dp"
app:thumb="#drawable/ic_progress_thumb"
android:layout_centerHorizontal="true" />
I tried setting setNestedScrollview to ViewCompact and also used focus in touch mode but output was same.
I have a RecyclerView which has children that expand on tap. I also have a CollapsingToolbarLayout at the top of this screen that collapses when the child of the RecyclerView expands. This is intended however when I then scroll on the RecyclerView, the collapsed view will suddenly expand to full size.
I assume this is happening because when the child is expanded and the toolbar collapses, it thinks the user has collapsed it on scroll. But because no touch was involved, when I subsequently scroll myself the RecyclerView still believes the view was where it was.
Any idea how to either stop the automatic collapsing or get the RecylerView to update with the position of the collapsed view?
Code, if necessary:
<android.support.design.widget.CoordinatorLayout
android:id="#+id/lytChanges"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="89dp"
android:background="#color/colorPrimary"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll">
<reroo.reroo.CustomViews.FontText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/itinerary_changes_margin_top"
android:background="#android:color/transparent"
android:text="Changes:"
android:textAlignment="center"
android:textColor="#B3ffffff"
android:textSize="16sp"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!--</android.support.percent.PercentRelativeLayout>-->
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="#color/grey"
android:focusable="false"
android:foreground="?android:attr/selectableItemBackground"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
EDIT 1: I have tried adding enterAlways, enterAlwaysCollapsed and exitUntilCollapsed to my xml but I believe this is an issue with the RecyclerView not tracking its position after it has animated with the child expanding.
EDIT 2: Using notifyItemChanged(position) after child tap causes the RecyclerView to animate the expansion and collapse, and then subsequently animate the un-collapsing of the view without any user input.
Preferred behaviour:
animate and collapse. Stay. or
don't animate and collapse, but collapse on scroll