【问题标题】:Android: how to hide the button when the scroll reach the endAndroid:滚动到达末尾时如何隐藏按钮
【发布时间】:2018-06-04 04:40:07
【问题描述】:

我的布局在顶部有滚动视图,在屏幕底部有按钮。我想在向下滚动时隐藏此按钮,并在到达滚动视图末尾时显示它。我怎么能意识到这一点?

红色-ButtonScrollView-蓝色。

【问题讨论】:

  • 在此处添加您的代码
  • 里面是scrollview还是list / recyclerview?不显示您尝试过的内容将不容易回答您。

标签: android layout android-coordinatorlayout


【解决方案1】:

试试这个 ma​​in_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);
                        }
                    }
                });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-06
    • 2023-02-23
    相关资源
    最近更新 更多