Floatingactionbutton using Relativelayout

Asked

Viewed 84 times

-2

Whenever I drag the Floatingactionbutton, it always goes back to the top left corner. Even using Relativelayout. I’m using Androidstudio 3.6

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        app:srcCompat="@mipmap/ic_launcher" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </ListView>
</RelativeLayout>

1 answer

0

Andre, you need to fix the button in the margins.

That’s how it works.

<android.support.design.widget.FloatingActionButton
    android:id="@+id/floatingActionButton9"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_marginEnd="@dimen/default_18dp"
    android:layout_marginBottom="@dimen/default_18dp"
    android:layout_marginTop="0dp"
    android:clickable="true"
    app:srcCompat="@mipmap/ic_launcher" />

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ListView>

I advise using Constraintlayout to make your screens. Give a googada

Browser other questions tagged

You are not signed in. Login or sign up in order to post.