国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

使用FloatingActionButton滑動消失后不再顯示問題

2019-11-06 09:52:28
字體:
來源:轉載
供稿:網友

FloatingActionButton的滑動顯示與隱藏的效果,相信很多app都加入了這一功能,但是最近將buildToolsVersion 升級到’25.0.2’,還有幾個支持庫也升級到compile ‘com.android.support:X 25.1.0’之后遇到一問題就是,FloatingActionButton可以正常顯示,但是列表上滑動隱藏后,再向下滑動,FloatingActionButton不在顯示出來。Google搜到了一個stackoverflow的回答:http://stackoverflow.com/a/41386278/1038102,

Calling child.hide() on the floating action button sets the view’s visibility to View.GONE, which means now (as of 25.1.0), the onNestedScroll method call will be skipped for the floating action button in the future (because it skips all views whose visibility is GONE).

對于25.1.0版本來說對floating action button設置View.GONE,floating action button就回跳過執行onNestedScroll方法(它會跳過所有visibility為GONE的views)

按照他的思路我修改了自己的Behavior

將其中的view.setVisibility(View.GONE);改為view.setVisibility(View.INVISIBLE);這樣又可以愉快的滑動顯示與隱藏了

public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior { PRivate static final Interpolator INTERPOLATOR = new FastOutSlowInInterpolator(); private boolean mIsAnimatingOut = false; public ScrollAwareFABBehavior(Context context, AttributeSet attrs) { super(); } @Override public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, final View directTargetChild, final View target, final int nestedScrollAxes) { // Ensure we react to vertical scrolling return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL || super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes); } @Override public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, final View target, final int dxConsumed, final int dyConsumed, final int dxUnconsumed, final int dyUnconsumed) { super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); if (dyConsumed > 0 && !this.mIsAnimatingOut && child.getVisibility() == View.VISIBLE) { // User scrolled down and the FAB is currently visible -> hide the FAB animateOut(child); } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) { // User scrolled up and the FAB is currently not visible -> show the FAB animateIn(child); } } // Same animation that FloatingActionButton.Behavior uses to hide the FAB when the AppBarLayout exits private void animateOut(final FloatingActionButton button) { if (Build.VERSION.SDK_INT >= 14) { ViewCompat.animate(button).translationY(button.getHeight() + getMarginBottom(button)).setInterpolator(INTERPOLATOR).withLayer() .setListener(new ViewPropertyAnimatorListener() { public void onAnimationStart(View view) { ScrollAwareFABBehavior.this.mIsAnimatingOut = true; } public void onAnimationCancel(View view) { ScrollAwareFABBehavior.this.mIsAnimatingOut = false; } public void onAnimationEnd(View view) { ScrollAwareFABBehavior.this.mIsAnimatingOut = false; view.setVisibility(View.INVISIBLE); } }).start(); } else { } } // Same animation that FloatingActionButton.Behavior uses to show the FAB when the AppBarLayout enters private void animateIn(FloatingActionButton button) { button.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= 14) { ViewCompat.animate(button).translationY(0) .setInterpolator(INTERPOLATOR).withLayer().setListener(null) .start(); } else { } } private int getMarginBottom(View v) { int marginBottom = 0; final ViewGroup.LayoutParams layoutParams = v.getLayoutParams(); if (layoutParams instanceof ViewGroup.MarginLayoutParams) { marginBottom = ((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin; } return marginBottom; }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 庆安县| 临朐县| 无锡市| 朔州市| 商水县| 荥阳市| 凤城市| 宣化县| 日喀则市| 清丰县| 莱州市| 呼图壁县| 南宫市| 绥滨县| 油尖旺区| 安顺市| 定西市| 蒲城县| 玉溪市| 蚌埠市| 贡山| 江孜县| 枣庄市| 土默特左旗| 尤溪县| 龙里县| 辉南县| 富锦市| 嵊州市| 衡山县| 南投县| 新疆| 张北县| 孟连| 隆昌县| 来凤县| 安徽省| 县级市| 阿城市| 瑞昌市| 灵宝市|