3

floatingactionbutton要素を使用しようとしましたが、UIレイアウトで浮動しません。浮動ボタンはレイアウトの一部を占め、コンポーネント上にはありません。ケースはFAB(浮動アクションボタン)は浮動しません

button doesn't float

、viewpagerですこれは私のレイアウトです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    tools:context="com.frases.frases.FraseMain" 
    android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/appbar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:minHeight="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" > 

    </android.support.v7.widget.Toolbar> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/sliding_tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed"/> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/white" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:src="@android:drawable/ic_dialog_email" /> 


</LinearLayout> 

答えて

5

これは、ルートレイアウトとしてLinearLayoutを使用しているためです。要素を重ねるにはFrameLayoutが必要で、FABは他のすべてのビューの上にとどまる必要があるため、最後の子ノードにする必要があります。

<FrameLayout> 
    <LinearLayout> 
    ... 
    </LinearLayout> 

    <!-- FAB be the last node inside FrameLayout here --> 
    <android.support.design.widget.FloatingActionButton /> 
</FrameLayout> 
+0

ありがとう、私はあなたの貢献とRitenの貢献で問題を解決しました –

+0

私は助けてくれるとうれしいです:-) –

+0

ソフトキーボードが表示されている場合、これは動作していないようです。 –

0

あなたLinearLayoutCoordinatorLayoutには変更できますか?

0
以下のような

使用CoordinatorLayout:

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/main_content" 
    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.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/appbar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:minHeight="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" > 

    </android.support.v7.widget.Toolbar> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/sliding_tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed"/> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/white" /> 

      <android.support.design.widget.FloatingActionButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom|right" 
       android:layout_margin="16dp" 
       android:src="@drawable/ic_done" 
       app:layout_anchor="@id/lvToDoList" 
       app:layout_anchorGravity="bottom|right|end" /> 

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

私は、あなたは、単にだけでなく、コードの下で、フローティングボタンを使用することができます、あなたはコーディネーターのレイアウトを使用する必要はないと思います。

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/dashboard_bg" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<!-- here you can have your viewpager --> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/dashboardShowActionsFab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:elevation="4dp" 
    app:fabSize="normal" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="26dp" 
    android:layout_marginBottom="16dp" /> 

</RelativeLayout> 

これが役に立ちます。

+0

ありがとう、それはうまくいく、私はあなたの貢献との問題を解決した。 –

+0

うわー...お元気ですか...お手伝いをすれば、答えを受け入れることができます。:D – Riten

関連する問題