Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

FAB não aparece e gera erro no XML

Boa noite. Após inserir o FAB e converter o layout para "Relative Layout", o XML ficou assim :

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


    <ListView
        android:id="@+id/activity_main_lv_alunos"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/floatingActionButton4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:focusable="true"
        app:srcCompat="@drawable/ic_launcher_background"></com.google.android.material.floatingactionbutton.FloatingActionButton>


</RelativeLayout>

Porém, ao arrastar o FAB, o XML fica bugado, colocando o FAB como filho do List View, gerando um erro e deixando o XML assim:

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


    <ListView
        android:id="@+id/activity_main_lv_alunos"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="153dp"
        android:layout_marginTop="191dp">

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/floatingActionButton4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="true"
            app:srcCompat="@drawable/ic_launcher_background"></com.google.android.material.floatingactionbutton.FloatingActionButton>
    </ListView>


</RelativeLayout>

Agora, como que faço para arrastar o FAB sem bugar? Já deixei o código conforme exibido em algumas soluções, porém não funcionou do mesmo jeito.

1 resposta
solução!

Boa noite. Para quem vem enfrentando esse mesmo problema, consegui resolver deste modo:

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

        <ListView
            android:id="@+id/activity_main_lv_alunos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </ListView>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/activity_main_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="35dp"
        android:layout_marginEnd="35dp"
        android:clickable="true"
        android:src="@mipmap/ic_plus_one_white_36dp">

    </com.google.android.material.floatingactionbutton.FloatingActionButton>


</RelativeLayout>

Desconsidere o parâmetro src, pois eu utilizei um ícone de uma biblioteca própria.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software