隐藏和重新出现浮动操作按钮,android
Hide and re-appear floating action button, android
我在 android 应用程序中使用浮动操作按钮。当用户向下滚动列表时,我实现了一项功能,FAB 消失了。当用户向上滚动时它会返回。
myRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy >0) {
// Scroll Down
if (floatingActionButton.isShown()) {
floatingActionButton.hide();
}
}
else if (dy <0) {
// Scroll Up
if (!floatingActionButton.isShown()) {
floatingActionButton.show();
}
}
}
});
即使用户没有向上滚动,如何让 FAB 在 5 秒后重新出现?
如果您对我的问题仍然不清楚,可以在 LinkedIn android 应用程序中查看此功能。
使用View.postDelayed()线程。
例如:
floatingActionButton.postDelayed(new Runnable() {
@Override
public void run() {
floatingActionButton.show();
}
},5000);
您可以使用 Timertask class 或者可以使用 runnable 和 handler
我在 android 应用程序中使用浮动操作按钮。当用户向下滚动列表时,我实现了一项功能,FAB 消失了。当用户向上滚动时它会返回。
myRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy >0) {
// Scroll Down
if (floatingActionButton.isShown()) {
floatingActionButton.hide();
}
}
else if (dy <0) {
// Scroll Up
if (!floatingActionButton.isShown()) {
floatingActionButton.show();
}
}
}
});
即使用户没有向上滚动,如何让 FAB 在 5 秒后重新出现? 如果您对我的问题仍然不清楚,可以在 LinkedIn android 应用程序中查看此功能。
使用View.postDelayed()线程。 例如:
floatingActionButton.postDelayed(new Runnable() {
@Override
public void run() {
floatingActionButton.show();
}
},5000);
您可以使用 Timertask class 或者可以使用 runnable 和 handler