1

私は、このレイアウト無効FABのフェードアニメーション

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="me.myapplication.ScrollingActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/app_bar_height" 
     android:fitsSystemWindows="true" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/toolbar_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/AppTheme.PopupOverlay"/> 

     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_scrolling"/> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" 
     app:layout_anchor="@id/app_bar" 
     app:layout_anchorGravity="bottom|end" 
     app:srcCompat="@android:drawable/ic_dialog_email"/> 

</android.support.design.widget.CoordinatorLayout> 

を持っており、FABはフェードインダウンとアウト - >video

は、このフェードアニメーションを無効にすることは可能ですか?

+0

のようになりますか?常に固定されたFABを使用してツールバーを折りたたんでいますか?サイズを小さくする必要がありますか? – Gaket

+0

将来の読者の方へ:答えは質問を明確にします。私はFloatingActionButtonのbehavior_autoHide属性が機能していなかった理由を理解しようとしていたので、この質問+答えを見つけました。 – amcnabb

答えて

2

は私が

FloatingActionButtonBehaviorbehavior_autoHideオプションを持っている:-)それを見つけました。

問題はレイアウトxmlでこのオプションを設定しようとしたことでした。しかし、FloatingActionButton.Behaviorは、Androidが間違ったコンストラクタを呼び出すため、このオプションを読みませんでした。

public Behavior() { 
    super(); 
    mAutoHideEnabled = AUTO_HIDE_DEFAULT; 
} 

レイアウトxmlにもBehaviorを設定する必要があります。 Androidは正しいコンストラクタを呼び出し、behavior_autoHideフラグが読み込まれます。

public Behavior(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    TypedArray a = context.obtainStyledAttributes(attrs, 
      R.styleable.FloatingActionButton_Behavior_Layout); 
    mAutoHideEnabled = a.getBoolean(
      R.styleable.FloatingActionButton_Behavior_Layout_behavior_autoHide, 
      AUTO_HIDE_DEFAULT); 
    a.recycle(); 
} 

あなたのレイアウトXMLの重要な部分は、正確にあなたが持っているしたいと思いますこれは何

<android.support.design.widget.FloatingActionButton 
    app:behavior_autoHide="false" 
    app:layout_anchor="@id/appbar" 
    app:layout_behavior="android.support.design.widget.FloatingActionButton$Behavior" 
    app:layout_anchorGravity="bottom|right|end"/> 
+0

素晴らしい仕事。バグを回避するには 'app:layout_behavior'行を追加するだけで十分です。 – amcnabb

0

フルテキスト検索:「FloatingActionButton.Behavior」を検索するには、Ctrl + Shift + Fを試してみてください。このクラスの後継はFABの動作を定義するので、このフェーディングを処理する行を削除することができます。 見つからない場合は、コーディネーターのレイアウトに適用され、FABに直接適用されない場合にのみ、「動作」を見つけてください。

+0

私はこのバーハイアを調べましたが、自動的に隠すオプションがありますが、これは私が探しているものではありません(または私は間違った方法で使用します) –

+0

このクラスをあなたの質問にも追加してください。 – Gaket

関連する問題