tôi đã cố gắng cập nhật com.android.support:appcompat
và com.android.support:design
từ: 25.0.1 đến 25.1.0, như sau:Floating nút hành động không hiển thị trên di chuyển sau khi cập nhật Google Hỗ trợ & Design Library
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
tới:
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
nhưng tôi thấy rằng nút tác vụ nổi của tôi không còn xuất hiện khi hoạt động cuộn. hành vi FAB của tôi được xác định bởi những điều sau đây:
public class MyFabBehavior extends FloatingActionButton.Behavior {
public MyFabBehavior(Context context, AttributeSet attrs) {
super();
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout,
FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) {
// Ensure we react to vertical scrolling
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
|| super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
}
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child,
View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
if (dyConsumed < 0) {
// User scrolled up -> hide the FAB
animateFab(child, View.GONE);
} else if (dyConsumed > 0) {
// User scrolled down -> show the FAB
animateFab(child, View.VISIBLE);
}
}
static public void animateFab(FloatingActionButton fab, int visibility) {
// ignore visibility passed in, and just make fab visible regardless
if (fab.getVisibility() != View.VISIBLE) {
fab.show();
}
}
}
và bố trí của tôi là như sau:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v4.widget.NestedScrollView
android:id="@+id/main_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp" >
...
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
app:layout_behavior="com.example.MyFabBehavior"
android:id="@+id/fab"
app:fabSize="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin"
android:onClick="saveButton"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_done_white_24dp" />
</android.support.design.widget.CoordinatorLayout>
Trong hộp thoại 'onCreate()' của 'Activity' tôi Tôi gọi 'hide() 'trên' FloatingActionButton', để nó bắt đầu ẩn và sau đó xuất hiện trên cuộn (thông qua hành vi đã xác định).Việc gọi 'hide()' có đặt hiển thị của nó thành 'GONE' và đoạn mã của bạn có cho thấy rằng nút hành động thả nổi được bỏ qua mãi mãi trong các sự kiện cuộn không? Chắc chắn không? – drmrbrewer