is RecyclerView Top - Android User Interface

Android examples for User Interface:RecyclerView

Description

is RecyclerView Top

Demo Code

import android.annotation.SuppressLint;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ScrollView;

public class Main {
  private static boolean isRecyclerViewTop(RecyclerView recyclerView) {
    if (recyclerView != null) {
      RecyclerView.LayoutManager layoutManager = recyclerView
          .getLayoutManager();//from  ww w  .ja v a2s .  c  o  m
      if (layoutManager instanceof LinearLayoutManager) {
        int firstVisibleItemPosition = ((LinearLayoutManager) layoutManager)
            .findFirstVisibleItemPosition();
        View childAt = recyclerView.getChildAt(0);
        if (childAt == null) {
          return true;
        }
        if (firstVisibleItemPosition == 0) {
          ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) childAt
              .getLayoutParams();
          int topMargin = lp.topMargin;
          int top = childAt.getTop();
          if (top >= topMargin) {
            return true;
          }
        }
      }
    }
    return false;
  }
}

Related Tutorials