2017-02-12 7 views
1

私は右下に浮動アクションボタンを持っていますが、明らかに重力が働いていません。左上隅に表示されます。ここに私のコードは次のとおりです。浮動アクションボタン重力が働かない

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/rl" 
      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"> 

<ImageView 
    android:id="@+id/iv" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

<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:layout_margin="16dp" 
    android:src="@mipmap/ic_action_send" 
    app:backgroundTint="@color/colorPrimaryDark" 
    app:layout_anchor="@id/iv" 
    app:layout_anchorGravity="bottom|right|end"/> 

</RelativeLayout> 

答えて

4

私は右下の 隅にある必要があり、フローティングアクションボタンを持っています明らかに重力は働いていません

CoordinatorLayoutの周りにコンテンツをラップしない限り、これは予想される動作です。例:

<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"> 


    <ImageView 
     android:id="@+id/iv" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

<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:layout_margin="16dp" 
     android:src="@mipmap/ic_action_send" 
     app:backgroundTint="@color/colorPrimaryDark" 
     app:layout_anchor="@id/iv" 
     app:layout_anchorGravity="bottom|right|end"/> 
</android.support.design.widget.CoordinatorLayout> 

する必要があります。その詳細については、CoordinatorLayouthere

+1

おかげで、これはトリックはなかったです。 –

0

使用android:layout_gravity="bottom|end"代わりapp:layout_anchorGravity="bottom|right|end"のは、エンド下(右下)の隅にそれを置くために

2

を使用してください。android:layout_alignParentBottom="true"android:layout_alignRight="@id/iv"をFloatingActionButtonパラメータとして使用してください。

0

でframeLayoutについて、あなたは試すことができます:

<FrameLayout 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" 
    android:fitsSystemWindows="true" 
    tools:context="ch13mob.wifiofworldairports.fragment.FragmentWifiAirports"> 

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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab_wifi" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/ic_wifi_black_24dp" /> 

</FrameLayout> 
関連する問題