RecyclerView recognize when reaching end of scroll

时间:2018-01-15 18:15:01

标签: android android-recyclerview

I have a RecyclerView using a horizontal GridView with two scrolling buttons on the sides (the app is ment for cars running android so i had to add additional buttons in addition to the ability to scroll the view).

Now I want to be able to dim the buttons when I reach the end of the scrolling, not just the last item, but literaly when there is no more to scroll.

I wasn't able to find a good solution yet!

2 个答案:

答案 0 :(得分:1)

您好,请将此添加到您的代码中:

在您的活动/片段/宣布recyclelerview的地方

RecyclerView rv; //Add your declare code (findViewById for example)
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    if (!recyclerView.canScrollHorizontally(1) ) {
        Toast.makeText(ChatDetailsActivity.this,"endOfScroll",Toast.LENGTH_LONG).show();
       //Implement button dim here. Example:
       //mybutton.setAlpha(0.5f);

    }
});

编辑:不确定是要垂直还是水平滚动 根据您的需要在if语句中将单词从水平更改为垂直

答案 1 :(得分:0)

recyclerView适配器 onBind()的{​​{1}}中添加此内容...而DisableButton是一个包含一个方法的接口if (position==lastItem) { DisableButton.dimButon();}并且在您的活动中创建一个字段变量dimButon();和你的onCreate使用DisableButton dim;

初始化它