0

私はフローティングアクションbuttomでリサイクルビューをレンダリングするフラグメントを持っています。問題は、リストが空であれば、ファブは右上を維持し、リストにはアイテムがほとんどなく、ファブはリストの下にありますが、リストが下になるのは、リスト全体が満杯になるまでですアイテムのある画面。誰かが私を助けてくれますか?ベローは私のコードです:Androidの浮動アクションボタンが底に固定されていません

<?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" 
    tools:context="com.app.juninho.financeapp.activity.FuncionarioActivity"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/funcionario_recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/btn_add_func" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|right|end" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="16dp" 
     android:src="@drawable/ic_menu_send" 
     app:layout_behavior="com.app.juninho.financeapp.utils.ScrollAwareFABBehavior" /> 

if the list is empty, fab keeps at the top, wich is wrongif the list has a few items, fab doesn't keep totaly at the bottom

Here is the correct way, fab is at the bottom

Using RelativeLayout it seems to work, but its too at the right/bottom corner

+0

問題は、このカスタムクラスにおそらくあるのに役立ちます:com.app.juninho.financeapp.utils.ScrollAwareFABBehavior – BladeCoder

+0

こんにちはBladeCoder!ご回答有難うございます!このカスタムクラスは、リストをスクロールするときにファブを非表示にし、スクロールダウンするときに表示します。私はこれを削除しようとしましたが、問題は続く... –

+0

CoordinatorLayoutをFramelayout/RelativeLayoutに置き換えることはできますか? –

答えて

0

問題があなたのFAB属性です:app:layout_behavior="com.app.juninho.financeapp.utils.ScrollAwareFABBehavior"

FABでこれを追加する必要はありません。この属性を削除し、属性app:layout_anchor="@id/funcionario_recycler_view"app:layout_anchorGravity="bottom|right|end"FABanchorに追加してください。RecyclerViewです。以下のように

アップデートレイアウト:

<?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" 
    tools:context="com.app.juninho.financeapp.activity.FuncionarioActivity"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/funcionario_recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/btn_add_func" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|right|end" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="16dp" 
     android:src="@drawable/ic_menu_send" 
     app:layout_anchor="@id/funcionario_recycler_view" 
     app:layout_anchorGravity="bottom|right|end" /> 
</android.support.design.widget.CoordinatorLayout> 

#。あなたがFABRecyclerViewをスクロールしたとき、あなたは以下のようにJavaコードでそれをpragmaticallyを行うことができます表示/非表示にする場合:

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.funcionario_recycler_view); 
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.btn_add_func); 

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() 
{ 
    @Override 
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) 
    { 
     if (dy > 0 ||dy<0 && fab.isShown()) 
     { 
      fab.hide(); 
     } 
    } 

    @Override 
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) 
    { 
     if (newState == RecyclerView.SCROLL_STATE_IDLE) 
     { 
      fab.show(); 
     } 

     super.onScrollStateChanged(recyclerView, newState); 
    } 
}); 

希望これは〜

+0

RecyclerViewは移動せず、FABはレイアウトの右下に留まるので、アンカーは必要ありません。 – BladeCoder

+0

はい、あなたは正しいです。レイアウトアンカーはここでは必要ありません。 – FAT

+0

こんにちは!残念ながら、それはうまくいきませんでした。私はそれをあきらめようとしています...それは同じ行動を保ちます。私はこのリサイクルビューとこのファブを使用していることを忘れていました。その中には、その中にrecycleviewアダプターを設定しているフラグメントがあります。その中にはonViewCreateがあり、私はスナックバーを使用していません。私のアプリには1つのアクティビティしかありません。ナビゲーション・ドロワーとFrameLayoutを持っていれば、私のフラグメントのレイアウトをすべて表示できます。他に何かできますか?あなたの助けをありがとう! –

関連する問題