答案 0 :(得分:3)
试试这个 的 main_layout.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Submit" />
</android.support.design.widget.CoordinatorLayout>
在活动类
中 RecyclerView mRecyclerView = findViewById(R.id.recycler_view);
Button mSubmit = findViewById(R.id.submit);
mRecyclerView .addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
//dx horizontal distance scrolled in pixels
//dy vertical distance scrolled in pixels
super.onScrolled(recyclerView, dx, dy);
if (dy > 0 && mSubmit.getVisibility() == View.VISIBLE) {
mSubmit.setVisibility(View.GONE);
} else if (dy < 0 && mSubmit.getVisibility() != View.VISIBLE) {
mSubmit.setVisibility(View.VISIBLE);
}
}
});