3

Я использовал код от here. В моем случае это выглядит какПлавающая кнопка действия (FAB) над ListView в фрагменте в xml?

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".fragments.FragmentList" 
    android:orientation="vertical" 
    android:id="@+id/linear"> 

    <ListView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:fab="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/listView" /> 

</LinearLayout> 

<android.support.design.widget.CoordinatorLayout 

    android:id="@+id/rootLayout" 
    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:src="@drawable/ic_add_white_24dp" 
    android:layout_gravity="bottom|end" 
    fab:elevation="6dp" 
    fab:pressedTranslationZ="12dp" 
    fab:backgroundTint="@color/accent" 
    app:layout_anchor="@id/listView"/> 
</android.support.design.widget.CoordinatorLayout> 

Но у меня есть «несколько тегов корневых» в Android Studio. Что я сделал не так? Пожалуйста, помогите мне, я не могу понять ((

+0

поместить все внутри координатора л ayout –

+0

Спасибо! Почему android: layout_gravity = "bottom | end" не работает? FAB находится слева и сверху –

ответ

2

Используйте этот макет вместо:

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".fragments.FragmentList" 
android:orientation="vertical" 
android:id="@+id/linear"> 

<ListView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:fab="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/listView" /> 


<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_add_white_24dp" 
    android:layout_gravity="bottom|end" 
    fab:elevation="6dp" 
    fab:pressedTranslationZ="12dp" 
    fab:backgroundTint="@color/accent" 
    app:layout_anchor="@id/listView"/> 

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

добавить 'android: fitSystemWindow =" true "' to 'CoordinatorLayout' –

0

изменение этой строки кода андроида: layout_gravity = "нижний | конец" к андроид: layout_gravity = "сверху "

+0

Мне нужно правое нижнее положение. Но это не работает. –

0
android:layout_alignParentBottom="true" 
android:layout_alignParentRight="true" 
android:layout_alignParentEnd="true" 

Это установит FAB правый нижний.

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