/* | |
* Copyright (C) 2017 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package your.package; | |
import android.content.Context; | |
import android.support.design.widget.AppBarLayout; | |
import android.support.design.widget.CoordinatorLayout; | |
import android.support.v4.view.ViewCompat; | |
import android.util.AttributeSet; | |
import android.view.View; | |
/** | |
* Workaround AppBarLayout.Behavior for https://issuetracker.google.com/66996774 | |
* | |
* See https://gist.github.com/chrisbanes/8391b5adb9ee42180893300850ed02f2 for | |
* example usage. | |
* | |
* Change the package name as you wish. | |
*/ | |
public class FixAppBarLayoutBehavior extends AppBarLayout.Behavior { | |
public FixAppBarLayoutBehavior() { | |
super(); | |
} | |
public FixAppBarLayoutBehavior(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
@Override | |
public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, | |
int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) { | |
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, | |
dxUnconsumed, dyUnconsumed, type); | |
stopNestedScrollIfNeeded(dyUnconsumed, child, target, type); | |
} | |
@Override | |
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, | |
View target, int dx, int dy, int[] consumed, int type) { | |
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type); | |
stopNestedScrollIfNeeded(dy, child, target, type); | |
} | |
private void stopNestedScrollIfNeeded(int dy, AppBarLayout child, View target, int type) { | |
if (type == ViewCompat.TYPE_NON_TOUCH) { | |
final int currOffset = getTopAndBottomOffset(); | |
if ((dy < 0 && currOffset == 0) | |
|| (dy > 0 && currOffset == -child.getTotalScrollRange())) { | |
ViewCompat.stopNestedScroll(target, ViewCompat.TYPE_NON_TOUCH); | |
} | |
} | |
} | |
} |
AppBarLayout abl = findViewById(R.id.app_bar); | |
((CoordinatorLayout.LayoutParams) abl.getLayoutParams()).setBehavior(new FixAppBarLayoutBehavior()); |
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout | |
android:id="@+id/app_bar" | |
android:layout_height="..." | |
android:layout_width="..." | |
app:layout_behavior="your.package.FixAppBarLayoutBehavior"> | |
</android.support.design.widget.AppBarLayout> | |
<!-- Content --> | |
</android.support.design.widget.CoordinatorLayout> |
This comment has been minimized.
This comment has been minimized.
This is exactly the best solution for this click bug. It works very well for me. |
This comment has been minimized.
This comment has been minimized.
well done man |
This comment has been minimized.
This comment has been minimized.
very gooD!! Thanks~ |
This comment has been minimized.
This comment has been minimized.
very nice. thank u |
This comment has been minimized.
This comment has been minimized.
thanks, finally solved the problem after searching for the whole morning |
This comment has been minimized.
This comment has been minimized.
Awesome! Thank you!!!!!!! |
This comment has been minimized.
This comment has been minimized.
Not working for me ...I have tried all ..but nothing working |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
@chrisbanes I use listview setNestedScrollingEnabled true instead of recyclerview, can't work. |
This comment has been minimized.
This comment has been minimized.
it works! thank you too much |
This comment has been minimized.
This comment has been minimized.
Can confirm that this works. |
This comment has been minimized.
This comment has been minimized.
excellent!! |
This comment has been minimized.
This comment has been minimized.
perfecto!!! |
This comment has been minimized.
This comment has been minimized.
Worked like a charm!! |
This comment has been minimized.
This comment has been minimized.
It also works on CollapsingToolbarLayout! Thank you very much. You saved my hours. |
This comment has been minimized.
This comment has been minimized.
It solves the fling problem but normal ACTION_MOVE does not work on RecyclerView (Horizontal) inside NestedScrollView |
This comment has been minimized.
This comment has been minimized.
thank u |
This comment has been minimized.
This comment has been minimized.
You are genius! Thank you. |
This comment has been minimized.
This comment has been minimized.
It works perfectly, but when I test on older Android like 4.1.1 the problem happens again, the button can't be click and only can scroll half of the screen. |
This comment has been minimized.
This comment has been minimized.
yeah, you can't expect this to be working on such old Android. |
This comment has been minimized.
This comment has been minimized.
Works perfect to me! Thanks, you saved me |
This comment has been minimized.
This comment has been minimized.
thank you . it works |
This comment has been minimized.
This comment has been minimized.
Nice, thank you man |
This comment has been minimized.
This comment has been minimized.
Amazing ! I lost a lot of time to recognize that it was the appbar... thanks a lot ! |
This comment has been minimized.
This comment has been minimized.
Works perfectly to me, thank you very much! |
This comment has been minimized.
This comment has been minimized.
Thanks!!! |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
You saved me :D Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks!!! |
This comment has been minimized.
This comment has been minimized.
Excellent work! This saved me a lot of headache. |
This comment has been minimized.
This comment has been minimized.
Mantap jiwa.. |
This comment has been minimized.
This comment has been minimized.
Works perfect! Thanks |
This comment has been minimized.
This comment has been minimized.
Not working for me on V27.1.1 |
This comment has been minimized.
This comment has been minimized.
Thanks so much i was wondering if there is any solution or not but now i am feeling very lucky thankyou so much |
This comment has been minimized.
This comment has been minimized.
Am having same issue with BottomSheetBehavior, any fix for that? |
This comment has been minimized.
This comment has been minimized.
Why isn't this incorporated in the official release so far? I have a Horizontal recyclerview inside a vertical recyclerview, which is inside a nestedscrollview. I'm now having issues with the usability of the horizontal scroll. It works very different from the Google Play app, which has good UX, I need to know if there's a standard solution for this provided by Android. |
This comment has been minimized.
This comment has been minimized.
@harsha-main I have the same layout with horizontal recycler inside a vertical recycler inside a coordinator layout. One think that fixed my issues with the app bar layout was setting |
This comment has been minimized.
This comment has been minimized.
Thanks!!! |
This comment has been minimized.
This comment has been minimized.
Thanks Chris ! |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Oh God!!! |
This comment has been minimized.
This comment has been minimized.
doesn't work for me, crashes!. |
This comment has been minimized.
This comment has been minimized.
Seems to be solved in the latest version of AndroidX dependencies |
This comment has been minimized.
This comment has been minimized.
doesn't work for me |
This comment has been minimized.
Thanks! Find the Kotlin version here.