How do I display the FloatingActionButton button?

2

Could you help me? I'm trying to make the FloatingActionButton button appear on my screen but it does not want to appear I do not know what else I'm doing ... I'm trying to solve this problem a long time but I can not solve:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
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"
android:background="#FFFFFF"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="br.com.gruporecursos.noamobile.AlertaFragment"
android:orientation="vertical">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/lstAlerta"
    android:dividerHeight="2dp"
    android:divider="#ECECEC"/>

    <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="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_menu_edit"
        />



    </LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
    
asked by anonymous 01.02.2017 / 20:29

1 answer

2

Use the CoordinatorLayout public class ), so you can use anchor "bottom|end" in your FloatingActionButton .

CoordinatorLayout provides an additional layer of control over touch events between your Views daughters. This is used by many components of the support library.

The CoordinatorLayout also gives your Views attributes the layout_anchor and layout_anchorGravity , which can be used to put some "Floating" view relative to another. For example, the FloatingActionButton anchored in the lower right corner. Here's how it should look:

<?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">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <ListView
            android:id="@+id/lstAlerta"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="#ECECEC"
            android:dividerHeight="2dp" />

    </android.support.v4.widget.SwipeRefreshLayout>

    <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="20dp"
        android:src="@android:drawable/ic_menu_edit" />
</android.support.design.widget.CoordinatorLayout>
    
02.02.2017 / 00:32