2015-06-27 3 views
3

Я добавил FloatingActionButton мое расположение внутри RelativeLayout, как следоватьКак сделать поддержку андроида FloatingActionButton в нижней правой части экрана?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/submit" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|right" 
     android:layout_margin="16dp" 
     android:clickable="true" 
     android:src="@drawable/ic_ok" /> 

</RelativeLayout> 

Как вы видите, я поставляю layout_gravity к bottom|right, но место моего FloatingActionButton не изменилось, и она лежит на верхнем левом углу.

Как я могу сделать свой FloatingActionButton внизу справа?

ответ

8

Использование CoordinatorLayout:

<?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" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<RelativeLayout 
    android:id="@+id/test" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

</RelativeLayout> 

<android.support.design.widget.FloatingActionButton 
    android:layout_margin="10dp" 
    android:id="@+id/myFAB" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:backgroundTint="#FF0000" 
    app:borderWidth="0dp" 
    app:elevation="8dp" 
    app:layout_anchor="@id/test" 
    app:layout_anchorGravity="bottom|right|end" /> 
</android.support.design.widget.CoordinatorLayout> 

Примечание

app:layout_anchor="@id/test" 
    app:layout_anchorGravity="bottom|right|end" 
+0

Спасибо, что работает отлично. – MChaker

+0

приветствуется – Blackbelt

+0

его тоже работает нормально, но я использовал madyx ответ –

7

Поскольку вы оборачивать ваш FloatingActionButton с RelativeLayout, использовать эти свойства вместо:

android:layout_alignParentBottom="true" 
android:layout_alignParentRight="true" 

Надеется, что это помогло.

+0

лучший ответ без каких-либо вещей дерьма .. спасибо –

+0

Добро пожаловать :) – madyx

0

Выемка из кода:

android:layout_gravity="bottom|right"

Добавьте эту строку:

app:layout_anchorGravity="bottom|right|end"

0

Выемка из кода:
андроида: layout_gravity = "Дно | право"

Добавить это:
приложение: layout_anchorGravity = "нижний | правый | конец"

Смежные вопросы