• 12

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Android onScrolled not called when View is set to GONE

I am trying to hide a RelativeLayout when I scroll up and show it when I scroll down. onScroll works fine and is invoked every time until View is set to GONE.

final RelativeLayout placeHeaderMain = findViewById(R.id.place_header_main);

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
        if (dy > 0) {
            // Scrolling up

        } else {
            // Scrolling down

I want my listener to continue working after setting the View to Gone in order to make it Visible when scrolled down.

Thanks in advance.

Are there enough items to be scrolled?

That code above won't be triggered if dy == 0. It could be not enough items to make the scroll and it will return dy equal to 0, father more it won't to call onScroll(...)

What dy do you have when RelativeLayout has hidden? Try to check that method below:

public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);
  • 1
Reply Report

Try to set the view to INVISIBLE and not to GONE.
when you set any view to View.GONE he is invisible and it doesn't take any space inside your layout , but when you set a view to View.INVISIBLE like before he will be invisible but unlike View.GONE your view still takes up space inside the layout.

  • 0
Reply Report
      • 1
    • Yes, I don't want the layout to take space. I want to hide it. The problem was that I don't have enough items to make the scroll.