欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android自定義FloatingActionButton滑動行為只隱藏不出現(xiàn)的問題小結

 更新時間:2017年01月03日 11:11:39   投稿:mrr  
這篇文章主要介紹了Android自定義FloatingActionButton滑動行為只隱藏不出現(xiàn)的問題小結,需要的朋友可以參考下

先來段Behavior代碼,網(wǎng)上關于FloatingActionButton(以下簡稱FAB)滑動的代碼很多了,參考一下。

public class FabBehavior extends FloatingActionButton.Behavior{
  private static final Interpolator INTERPOLATOR = new FastOutSlowInInterpolator();
  private boolean mIsAnimatingOut = false;
  public FabBehavior(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) {
              FabBehavior.this.mIsAnimatingOut = true;
            }
            public void onAnimationCancel(View view) {
              FabBehavior.this.mIsAnimatingOut = false;
            }
            public void onAnimationEnd(View view) {
              FabBehavior.this.mIsAnimatingOut = false;
              view.setVisibility(View.GONE);
            }
          }).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;
  }
}

這是自定義的一個Behavior類,主要在onNestedScroll中自定義了出現(xiàn)和消失的動畫。使用的時候,在xml文件中給FAB加一個包含完整behavior類名的layout_behavior屬性

app:layout_behavior="com.normalframe.widgets.view.FabBehavior"

這樣FAB就會隨著列表上滑消失,下滑出現(xiàn)。這個功能主要是要處理FAB的位置會使列表最后一項被擋住的問題,當上滑時,F(xiàn)AB隱藏,這樣當?shù)竭_列表底部最后一項時,由于剛剛的動作是上滑動作,所以FAB處于隱藏狀態(tài),不會遮擋到列表。

在寫這個功能時,發(fā)現(xiàn)了一個問題:

上滑時FAB能夠正常隱藏,但是下拉列表時,F(xiàn)AB就不出現(xiàn)了。

而一樣的代碼如果放到其它項目中,有些又可以正常實現(xiàn)功能。Debug的時候發(fā)現(xiàn),上拉時會調用onNestedScroll,于是其中自定義的隱藏方法可以被調用,但下滑時,不調用onNestedScroll。

以上所述是小編給大家介紹的Android自定義FloatingActionButton滑動行為只隱藏不出現(xiàn)的問題小結,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • Flutter 快速實現(xiàn)聊天會話列表效果示例詳解

    Flutter 快速實現(xiàn)聊天會話列表效果示例詳解

    這篇文章主要為大家介紹了Flutter 快速實現(xiàn)聊天會話列表效果示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • ExpandableListView實現(xiàn)二級列表購物車

    ExpandableListView實現(xiàn)二級列表購物車

    這篇文章主要為大家詳細介紹了ExpandableListView實現(xiàn)二級列表購物車,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Android OkHttp 結合php 多圖片上傳實例

    Android OkHttp 結合php 多圖片上傳實例

    本篇文章主要介紹了Android OkHttp 結合php 多圖片上傳實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 基于Android10渲染Surface的創(chuàng)建過程

    基于Android10渲染Surface的創(chuàng)建過程

    這篇文章主要介紹了基于Android10渲染Surface的創(chuàng)建過程,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-08-08
  • Android無需申請權限撥打電話的兩種方式

    Android無需申請權限撥打電話的兩種方式

    android 打電話有兩種實現(xiàn)方式,第一種方法撥打電話跳轉到撥號界面,第二種方法,撥打電話直接進行撥打,下面逐一給大家介紹這兩種方式,需要的朋友參考下吧
    2016-12-12
  • Android自定義textview實現(xiàn)豎直滾動跑馬燈效果

    Android自定義textview實現(xiàn)豎直滾動跑馬燈效果

    這篇文章主要為大家詳細介紹了Android自定義textview實現(xiàn)豎直滾動跑馬燈效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • android?studio實現(xiàn)簡易的計算器

    android?studio實現(xiàn)簡易的計算器

    這篇文章主要為大家詳細介紹了android?studio實現(xiàn)簡易的計算器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Android ViewModel的作用深入講解

    Android ViewModel的作用深入講解

    這篇文章主要介紹了Android ViewModel的作用,ViewModel類旨在以注重生命周期的方式存儲和管理界面相關數(shù)據(jù),ViewModel類讓數(shù)據(jù)可在發(fā)生屏幕旋轉等配置更改后繼續(xù)留存,需要詳細了解可以參考下文
    2023-05-05
  • Android HandlerThread案例詳解

    Android HandlerThread案例詳解

    這篇文章主要介紹了Android HandlerThread案例詳解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • Android自定義控件之繼承ViewGroup創(chuàng)建新容器

    Android自定義控件之繼承ViewGroup創(chuàng)建新容器

    這篇文章主要介紹了Android自定義控件之繼承ViewGroup創(chuàng)建新容器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12

最新評論