Java Code Examples for androidx.recyclerview.widget.RecyclerView#getViewTreeObserver()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#getViewTreeObserver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoColumnGridLayoutManager.java    From RecyclerExt with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the maximum number of columns based on the width of the items.
 * If the <code>recyclerView</code>'s width hasn't been determined yet, this
 * will register for the layout that will then perform the functionality to
 * set the number of columns.
 *
 * @param gridItemWidth The width for the items in each column
 * @return The number of allowed columns
 */
protected int determineColumnCount(int gridItemWidth) {
    RecyclerView recyclerView = parent.get();
    if (recyclerView == null) {
        return 1;
    }

    //We need to register for the layout then update the column count
    if (recyclerView.getWidth() == 0) {
        ViewTreeObserver observer = recyclerView.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new LayoutListener(recyclerView));
        return 1;
    }

    //Updates the actual column count and spacing between items
    int columnCount = getColumnCount(recyclerView, gridItemWidth);
    resetRecyclerPadding(recyclerView);
    updateSpacing(recyclerView, gridItemWidth, columnCount);

    return columnCount;
}
 
Example 2
Source File: RecyclerBinder.java    From litho with Apache License 2.0 5 votes vote down vote up
private void registerDrawListener(final RecyclerView view) {
  if (view instanceof HasPostDispatchDrawListener) {
    ((HasPostDispatchDrawListener) view)
        .registerPostDispatchDrawListener(mPostDispatchDrawListener);
  } else if (view.getViewTreeObserver() != null) {
    view.getViewTreeObserver().addOnPreDrawListener(mOnPreDrawListener);
  }
}
 
Example 3
Source File: RecyclerBinder.java    From litho with Apache License 2.0 5 votes vote down vote up
private void unregisterDrawListener(final RecyclerView view) {
  if (view instanceof HasPostDispatchDrawListener) {
    ((HasPostDispatchDrawListener) view)
        .unregisterPostDispatchDrawListener(mPostDispatchDrawListener);
  } else if (view.getViewTreeObserver() != null) {
    view.getViewTreeObserver().removeOnPreDrawListener(mOnPreDrawListener);
  }
}