gpt4 book ai didi

Android:如何在滚动结束时隐藏按钮

转载 作者:行者123 更新时间:2023-11-29 16:46:23 25 4
gpt4 key购买 nike

我的布局是 ScrollView 在顶部,按钮在屏幕底部。我想在向下滚动时隐藏此按钮,并在到达 ScrollView 末尾时显示它。我如何才能意识到这一点?

红色-ButtonScrollView-蓝色。

最佳答案

试试这个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>

Activity 类

    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);
}
}
});

关于Android:如何在滚动结束时隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47926039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com