FAB button does not stay in place [duplicate]

0

I do not know what's happening the FAB button goes up on top of another compile component, but in the preview it works fine.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="wrap_content"
    android:layout_height="wrap_content"
    tools:context="com.rbxsoft.rbxsalesforce.CaixaDeEntradaActivity">


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="0dp">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="@string/caixaDeEntrada"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="0dp" />


        <android.support.v7.widget.RecyclerView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:paddingTop="30dp"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="8dp">

        </android.support.v7.widget.RecyclerView>

    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabNovoPedido"
        android:layout_width="48dp"
        android:layout_height="53dp"
        android:layout_gravity="end|bottom"
        android:elevation="0dp"
        android:padding="4dp"
        android:src="@drawable/ic_plus"
        app:elevation="0dp"
        app:fabSize="normal"
        tools:layout_editor_absoluteX="292dp"
        tools:layout_editor_absoluteY="439dp" />

</android.support.constraint.ConstraintLayout>

    
asked by anonymous 05.12.2017 / 14:13

1 answer

3

It does not stay in place because you have not applied any constraint to it. And the editor should warn you with a warning sign. Attributes editor_absoluteY/X only serve to give a visual effect in the editor, they will not position your view as you want it to be.

Read a little about ConstraintLayout , because to position your views , you will need to connect them to each other, creating nodes . In the editor itself you can do that.

Another thing, none of your views are connected correctly, because you just played them in your Layout .

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="wrap_content"
    android:layout_height="wrap_content"
    tools:context="com.rbxsoft.rbxsalesforce.CaixaDeEntradaActivity">


    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="@string/caixaDeEntrada" />


        <android.support.v7.widget.RecyclerView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:paddingTop="30dp">

        </android.support.v7.widget.RecyclerView>

    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabNovoPedido"
        android:layout_width="48dp"
        android:layout_height="53dp"
        android:elevation="0dp"
        android:padding="4dp"
        android:src="@drawable/ic_plus"
        app:elevation="0dp"
        app:fabSize="normal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

</android.support.constraint.ConstraintLayout>

The above code should work as desired. Below I will explain some important things that I have added in your layout.

Note: 0dp is like mach_parent .

layout_constraintStart

This attribute will align the start of your view with another part of another view or parent ( which in the case is the Constraint Layout itself).

You can use it with the following attributes : _toStartOf and _toEndOf .

layout_constraintEnd

It's the same thing as the previous attribute, but it aligns the right part of your view with another view / parent .

>

Can be used with: _toStartOf and _toEndOf

layout_constraintTop

It is also the same as the previous one, but it aligns the top and remembers very much the attribute layout_below of RelativeLayout if combined with _toBottomOf .

Can be used with: _toTopOf and _toBottomOf .

layout_constraintBottom

Aligns bottom and remembers attribute layout_above of RelativeLayout if combined with _toTopOf .

Can be used with: _toTopOf and _toBottomOf .

    
05.12.2017 / 14:52