FloatingActionButton隐藏在列表滚动上
问题描述:
我使用android.support.design.widget
包中的FloatingActionButton
:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="20dp"
android:layout_marginEnd="16dp"
android:clickable="true"
android:backgroundTint="@color/primaryColor"
android:src="@drawable/ic_search_white_24dp"
app:borderWidth="0dp"
app:elevation="6dp"
app:backgroundTint="@color/primaryColorDark"
app:rippleColor="@color/accentColor" />
是否可以将该按钮配置为在列表视图向下滚动时与动画一起隐藏,并在列表视图向上滚动至顶部时再次显示?
Is it possible to configure that button to hide with an animation when the listview is scrolling down and to show it again when listview is scrolling up to the top?
答
请参见此一个>.在这里,它告诉您如何做您想达到的目标.您必须在CoordinatorLayout
和ListView
中像这样使用它:
See this. Here it tells how to do what you are trying to achieve. You have to use it like this in a CoordinatorLayout
and ListView
:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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/lvToDoList"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/ic_done"
app:layout_anchor="@id/lvToDoList"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>