How to make FAB overlap items in a ListView

1

I have an activity where I infold the custom items into a ListView. In the setContentView () of this activity I put a file that has only one declared ListView.

 <ListView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/list_exercicios"
     android:orientation="vertical"
     android:clickable="true"
     android:layout_width="match_parent"
     android:layout_height="match_parent"/>

In another XML file I create the layout of the items that go into the ListView.      

<LinearLayout
    android:id="@+id/exercicios_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/exercicios_background"
    android:orientation="vertical">

    <TextView
        android:id="@+id/pergunta"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/title_exercicios_background"
        android:gravity="center"
        android:text="Aqui vai a pergunta"
        android:textColor="@color/letras_exercicios"
        android:textSize="25sp" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/radio_button_a"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="Aqui vai a perunta"
            android:textColor="#FFFFFF"
            style="@android:style/Widget.CompoundButton.CheckBox"/>
        <RadioButton
            android:id="@+id/radio_button_b"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="Aqui vai a perunta"
            android:textColor="#FFFFFF"
            style="@android:style/Widget.CompoundButton.CheckBox"/>
        <RadioButton
            android:id="@+id/radio_button_c"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="Aqui vai a perunta"
            android:textColor="#FFFFFF"
            style="@android:style/Widget.CompoundButton.CheckBox"/>
        <RadioButton
            android:id="@+id/radio_button_d"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="Aqui vai a perunta"
            android:textColor="#FFFFFF"
            style="@android:style/Widget.CompoundButton.CheckBox"/>
        <RadioButton
            android:id="@+id/radio_button_e"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="Aqui vai a perunta"
            android:textColor="#FFFFFF"
            style="@android:style/Widget.CompoundButton.CheckBox"/>

    </RadioGroup>

    <TextView
        android:id="@+id/finished_question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/terminei_background"
        android:text="@string/txt_responder"
        android:textSize="25sp"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:onClick="terminou"/>

</LinearLayout>

The problem is that if I put the FAB in this file it appears in all the items and it does not work, and if I put it in the ListView file it gives an error.

    
asked by anonymous 22.08.2017 / 03:53

2 answers

0

Must use ConstraintLayout or FrameLayout Something like:

<LinearLayout 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:orientation="vertical">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView 
             android:id="@+id/list_exercicios"
             android:orientation="vertical"
             android:clickable="true"
             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:layout_gravity="end|bottom"
            android:layout_margin="16dp"
            android:src="@drawable/ic_done" />

    </FrameLayout>

</LinearLayout>
    
22.08.2017 / 16:02
0

Try this:

XML

<ListView
    android:id="@+id/list_exercicios"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true" />



<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:clickable="true"
    android:id="@+id/fab"
    android:src="@mipmap/ic_icon"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    />

Activity

public class SuaActivity extends AppCompatActivity {

   private FloatingActionButton fab;
    private ListView listaExercicio;

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.seu_xml);
         // Referencia da Lista
        listaExercicio = ListView.class.cast(findViewById(R.id.list_exercicios));
         // Referencia do Floating Action Button
        fab = FloatingActionButton.class.cast(findViewById(R.id.fab));
    }

}
    
22.08.2017 / 04:02