title: Find if a view is on screen in a recyclerview
body: <p>I'm working on an AndroidTV app. So I have a recyclerview that contains a horizontal linear layout with 5 items. During OnBindViewHolder I call viewholder.bind() and in there I change the width of the individual items dynamically. I then call getLocalVisibleRect() to see which of those views are actually on screen. Here is the issue though. It works for the initial screen, but when I scroll down the recyclerview, it is inconsistent with the results of if they are on screen or not. Here is where I set the length of the item and try to set it focusable if it is on screen or not.</p>
  
  <pre><code>    private void setProgramDataToView(Programme programme, TextView textView) {
          textView.setText(getEPGText(programme));
          textView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                  Rect r = new Rect();
                  boolean v = textView.getLocalVisibleRect(r);
                  textView.setFocusable(v);
                  textView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
              }
          });
  
          ViewGroup.LayoutParams layoutParams = textView.getLayoutParams();
          layoutParams.width = timeLineHelper.getDurationProgram(programme);
          textView.setLayoutParams(layoutParams);
      }
  </code></pre>
  
  <p>I've tried to change the GlobalLayoutListener to before or after changing the length, it doesn't make a difference it seems like. And since it works for the initial recyclerview items, it seems like the logic works. It seems like it could be a race condition, but while scrolling some of the items give the right results while the rest are very inconsistent. For example it will say views that are on screen are not on screen and views that are off screen are on screen. Any help would be appreciated.</p>