In a recent study Android, previously added in the interface of the ListView control to ensure FAB beautiful interface; behind the ListView want to be able to have a pull-down refresh feature, I am going to use Google's own controls SwipeRefreshLayout to complete the refresh.
-
Before modification activity_main.xml
<?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="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lvwStudent" android:layout_width="match_parent" android:layout_height="0dp" tools:ignore="MissingConstraints" tools:layout_editor_absoluteX="8dp" tools:layout_editor_absoluteY="8dp" /> <android.support.design.widget.FloatingActionButton android:id="@+id/floatingActionButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="4dp" android:layout_marginStart="8dp" android:clickable="true" android:focusable="true" app:fabSize="normal" app:layout_anchorGravity="end|center" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:srcCompat="@drawable/add" /> </android.support.constraint.ConstraintLayout>
In order to achieve the drop-down refresh demand, I will android.support.constraint.ConstraintLayout change for android.support.v4.widget.SwipeRefreshLayout .
After changing discovery FAB gone, baffled.
I think it should be provided with anchor and FAB relationship, but how to change not successful.
Think of a tricky way: the ListView and refresh function into another XML layout files, and then include references over.
-
student_list.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/swip_main_layout" xmlns:tools="http://schemas.android.com/tools"> <ListView android:id="@+id/lvwStudent" android:layout_width="match_parent" android:layout_height="0dp" tools:ignore="MissingConstraints" tools:layout_editor_absoluteX="8dp" tools:layout_editor_absoluteY="8dp" /> </android.support.v4.widget.SwipeRefreshLayout>
-
activity_main.xml
<?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="match_parent" android:layout_height="match_parent"> <include android:layout_height="match_parent" android:layout_width="match_parent" layout="@layout/student_list"/> <android.support.design.widget.FloatingActionButton android:id="@+id/floatingActionButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="4dp" android:layout_marginStart="8dp" android:clickable="true" android:focusable="true" app:fabSize="normal" app:layout_anchorGravity="end|center" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:srcCompat="@drawable/add" /> </android.support.constraint.ConstraintLayout>
And then show you the real machine
problem solved
/*************************************************************************************************/
In the subsequent discovery learning process, SwipeRefreshLayout may like this use, the effect can be reached
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swip_main_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lvwStudent" android:layout_width="match_parent" android:layout_height="0dp" /> </android.support.v4.widget.SwipeRefreshLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/floatingActionButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="4dp" android:layout_marginStart="8dp" android:clickable="true" android:focusable="true" app:fabSize="normal" app:layout_anchorGravity="end|center" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:srcCompat="@drawable/add" />