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.
Related
Here is my Persistent BottomSheet
<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:id="#+id/bs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bottom_sheet_background"
android:elevation="2dp"
android:padding="#dimen/base_margin"
app:behavior_hideable="true"
app:behavior_peekHeight="#dimen/bottom_sheet_peek_height"
app:layout_behavior="#string/bottom_sheet_behavior">
When User scrolls RecycleView, BottomNavigation hides and I reduce height of BottomSheet accordingly in RecycleView's addOnScrollListener using:
binding.rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
//148 = 80(bottom navigation) + 56(bottom sheet)
if (dy < 0)//scroll down
bottomSheetBehavior.setPeekHeight(136, true);
else if (dy > 0)//scroll up
bottomSheetBehavior.setPeekHeight(56, true);
}
After BottomNavigation is hidden and BottomSheet height is reduced, if BottomSheet is clickable,
(either through code binding.bs.bs.setClickable(false); or through xml android:clickable="true")
I can't drag it to expand. If it is not clickable, click event goes through it and user click on RecycleView item underneath it.
Even when its height is not reduced and it isn't clickable then also click event goes under it and fire on RecycleView item.
I also tried setting nestedScrolling, which allowed expanding but after that start creating issues when collapsing. :(
UPDATE:
I noticed BottomSheet drag not works when I set Bottomsheet clickable and its peekheight < 80 dp, ie the height of BottomNavigation.
Reference:
Why am I able to click "behind" the bottomsheet in Android?
I had same use case of having a recycler view inside a bottom sheet and here's what my Bottom sheet XML looks like. Please try to check if this works for you!
Apart from this, I did not actually get it why you want to reduce the height of the bottom sheet, as Bottom sheet has the behavior of self adjusting its height respect to the content inside it.
Please if possible share your use case so that it will be easier for the community to answer which gonna hit the bonsai. Thanks!
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:background="#color/transparent"
android:layout_height="match_parent"
android:paddingTop="50dp"
android:id="#+id/rootLayout"
>
<include
android:id="#+id/progress"
layout="#layout/item_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/rootView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bottom_sheet_rounded_background"
android:backgroundTint="#color/background_gray"
android:clipToPadding="true"
android:orientation="vertical"
app:layout_behavior="#string/bottom_sheet_behavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<RelativeLayout
android:id="#+id/title_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="24dp"
android:height="24sp"
android:fontFamily="#font/silka_bold"
android:text="#string/error_select_prescription"
android:textColor="#color/text_color_semi_black"
android:textSize="16sp" />
<ImageView
android:id="#+id/iv_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:src="#drawable/ic_close_btn_gray" />
</RelativeLayout>
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/btn_gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/title_rl" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewPrescription"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingTop="#dimen/dimen_16dp"
tools:itemCount="10" />
</androidx.core.widget.NestedScrollView>
<include
android:id="#+id/btn_select_and_proceed"
layout="#layout/sticky_footer_design_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
val bottomSheet = dialog!!.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout
val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from<View>(bottomSheet)
behavior.state = BottomSheetBehavior.STATE_EXPANDED
These all are the states which you can use to manipulate the height or basically the behavior of the BottomSheet.
I have two RecyclerView, both have a vertical orientation, I need to scroll one of them so that the second scrolls, that is, their scrolling is synchronous, I thought that it is possible to apply one LinearLayoutManager to these two RecyclerView and then it will be work, but in this log, the error LinearLayoutManager is already attached to a RecyclerView will be generated, so I don't know how to be, help me find a solution, I need two independent RecyclerView with different adapters, but which scroll synchronously, so do not write about GridLayoutManager, thanks.
xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clipToPadding="false"
android:orientation="vertical"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clipToPadding="false"
android:orientation="vertical"/>
</LinearLayout>
Cod
val RLM_0 = LinearLayoutManager(context)
rv_0.setHasFixedSize(false)
rv_0.isNestedScrollingEnabled = false
rv_0.layoutManager = RLM_0
adapter_0 = Adapter_0(itemTasks, requireActivity())
rv_0.adapter = adapter_0
val RLM_1 = LinearLayoutManager(context)
rv_1.setHasFixedSize(false)
rv_1.isNestedScrollingEnabled = false
rv_1.layoutManager = RLM_1
adapter_1 = Adapter_1(itemTasks, requireActivity())
rv_1.adapter = adapter_1
Solution 1:
Check is: Sync scrolling of multiple RecyclerViews
Solution 2:
There is an other way to do so, the idea is to disable scroll for each recycler view and surround them with a scroll view.
This is how you can implement it:
binding.recyclerViewOne.setOnTouchListener((v, event) -> true);
binding.recyclerViewTwo.setOnTouchListener((v, event) -> true);
And for the layout:
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
</ScrollView>
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 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
My RecyclerView contains a list of CardView
xml for MainActivity:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.RecyclerView
android:id="#+id/view_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
<FloatingActionButton/>
</android.support.design.widget.CoordinatorLayout>
I use an adapter for the RecyclerView above to contain the Cards.
xml used to inflate ViewHolder inside the adapter:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout"
android:paddingTop="2dp"
android:paddingRight="2dp"
android:paddingLeft="2dp"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<android.support.v7.widget.CardView
android:id="#+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardBackgroundColor="#android:color/holo_red_light"
card_view:cardPreventCornerOverlap="true"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="3dp"
card_view:contentPadding="7dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:id="#+id/relat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="false"
android:padding="10dp">
<TextView/>
//...
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
To make the Cards clickable, I tried all solutions in these - two popular posts , but I always have this weird bug:
The list of Cards won't scroll when I start the app for the first time, unless I click on the RecyclerView once. It's as if the RecyclerView is not in focus initially.
Also, if I get rid of all click listeners or similar ways to make the CardView's clickable, and only keep the focusable code in xml:
android:focusable="true"
android:focusableInTouchMode="false"
, then it does scroll right away, but as soon as I add any click (listener) mechanism, or even include "android:clickable="true"" for the ViewHolder, that bug re-emerges.
Please advise. Thank you
You should never nest a RecyclerView inside a ScrollView. Just remove the NestedScrollView and the RecyclerView should take care of its scrolling behavoiur.
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/view_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
Turns out the scrolling issue is not related to the RecyclerView. It was due to an open source widget I used which anchored to the RV and somehow interfered with the focusing/scrolling/touch interception. Finally got rid of this bug after days of looking elsewhere..
thank you all the same