public class

VerticalGridView

extends BaseGridView

 java.lang.Object

↳ViewGroup

androidx.recyclerview.widget.RecyclerView

androidx.leanback.widget.BaseGridView

↳androidx.leanback.widget.VerticalGridView

Gradle dependencies

compile group: 'androidx.leanback', name: 'leanback-grid', version: '1.0.0-alpha01'

  • groupId: androidx.leanback
  • artifactId: leanback-grid
  • version: 1.0.0-alpha01

Artifact androidx.leanback:leanback-grid:1.0.0-alpha01 it located at Google repository (https://maven.google.com/)

Androidx class mapping:

androidx.leanback.widget.VerticalGridView android.support.v17.leanback.widget.VerticalGridView

Overview

A android.view.ViewGroup that shows items in a vertically scrolling list. The items come from the associated with this view.

can optionally implement FacetProviderAdapter which provides FacetProvider for a given view type; can also implement FacetProvider. Facet from ViewHolder has a higher priority than the one from FacetProviderAdapter associated with viewType. Supported optional facets are:

  1. ItemAlignmentFacet When this facet is provided by ViewHolder or FacetProviderAdapter, it will override the item alignment settings set on VerticalGridView. This facet also allows multiple alignment positions within one ViewHolder.

Summary

Fields
from BaseGridViewFOCUS_SCROLL_ALIGNED, FOCUS_SCROLL_ITEM, FOCUS_SCROLL_PAGE, ITEM_ALIGN_OFFSET_PERCENT_DISABLED, SAVE_ALL_CHILD, SAVE_LIMITED_CHILD, SAVE_NO_CHILD, SAVE_ON_SCREEN_CHILD, WINDOW_ALIGN_BOTH_EDGE, WINDOW_ALIGN_HIGH_EDGE, WINDOW_ALIGN_LOW_EDGE, WINDOW_ALIGN_NO_EDGE, WINDOW_ALIGN_OFFSET_PERCENT_DISABLED
from RecyclerViewHORIZONTAL, INVALID_TYPE, NO_ID, NO_POSITION, SCROLL_STATE_DRAGGING, SCROLL_STATE_IDLE, SCROLL_STATE_SETTLING, TOUCH_SLOP_DEFAULT, TOUCH_SLOP_PAGING, UNDEFINED_DURATION, VERTICAL
Constructors
publicVerticalGridView(Context context)

publicVerticalGridView(Context context, AttributeSet attrs)

publicVerticalGridView(Context context, AttributeSet attrs, int defStyle)

Methods
protected voidinitAttributes(Context context, AttributeSet attrs)

public voidsetNumColumns(int numColumns)

Sets the number of columns.

from BaseGridViewaddOnChildViewHolderSelectedListener, addOnLayoutCompletedListener, animateIn, animateOut, dispatchGenericFocusedEvent, dispatchKeyEvent, dispatchTouchEvent, focusSearch, getChildDrawingOrder, getExtraLayoutSpace, getFocusScrollStrategy, getHorizontalMargin, getHorizontalSpacing, getInitialPrefetchItemCount, getItemAlignmentOffset, getItemAlignmentOffsetPercent, getItemAlignmentViewId, getOnUnhandledKeyListener, getSaveChildrenLimitNumber, getSaveChildrenPolicy, getSelectedPosition, getSelectedSubPosition, getSmoothScrollByBehavior, getSmoothScrollMaxPendingMoves, getSmoothScrollSpeedFactor, getVerticalMargin, getVerticalSpacing, getViewSelectedOffsets, getWindowAlignment, getWindowAlignmentOffset, getWindowAlignmentOffsetPercent, hasOverlappingRendering, hasPreviousViewInSameRow, isChildLayoutAnimated, isFocusDrawingOrderEnabled, isFocusSearchDisabled, isItemAlignmentOffsetWithPadding, isScrollEnabled, isWindowAlignmentPreferKeyLineOverHighEdge, isWindowAlignmentPreferKeyLineOverLowEdge, onFocusChanged, onRequestFocusInDescendants, onRtlPropertiesChanged, removeOnChildViewHolderSelectedListener, removeOnLayoutCompletedListener, removeView, removeViewAt, scrollToPosition, setAnimateChildLayout, setChildrenVisibility, setExtraLayoutSpace, setFocusDrawingOrderEnabled, setFocusScrollStrategy, setFocusSearchDisabled, setGravity, setHasOverlappingRendering, setHorizontalMargin, setHorizontalSpacing, setInitialPrefetchItemCount, setItemAlignmentOffset, setItemAlignmentOffsetPercent, setItemAlignmentOffsetWithPadding, setItemAlignmentViewId, setItemMargin, setItemSpacing, setLayoutEnabled, setLayoutManager, setOnChildLaidOutListener, setOnChildSelectedListener, setOnChildViewHolderSelectedListener, setOnKeyInterceptListener, setOnMotionInterceptListener, setOnTouchInterceptListener, setOnUnhandledKeyListener, setPruneChild, setSaveChildrenLimitNumber, setSaveChildrenPolicy, setScrollEnabled, setSelectedPosition, setSelectedPosition, setSelectedPosition, setSelectedPositionSmooth, setSelectedPositionSmooth, setSelectedPositionSmoothWithSub, setSelectedPositionWithSub, setSelectedPositionWithSub, setSmoothScrollByBehavior, setSmoothScrollMaxPendingMoves, setSmoothScrollSpeedFactor, setVerticalMargin, setVerticalSpacing, setWindowAlignment, setWindowAlignmentOffset, setWindowAlignmentOffsetPercent, setWindowAlignmentPreferKeyLineOverHighEdge, setWindowAlignmentPreferKeyLineOverLowEdge, smoothScrollBy, smoothScrollBy, smoothScrollToPosition
from RecyclerViewaddFocusables, addItemDecoration, addItemDecoration, addOnChildAttachStateChangeListener, addOnItemTouchListener, addOnScrollListener, addRecyclerListener, checkLayoutParams, clearOnChildAttachStateChangeListeners, clearOnScrollListeners, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPreScroll, dispatchNestedPreScroll, dispatchNestedScroll, dispatchNestedScroll, dispatchNestedScroll, dispatchPopulateAccessibilityEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, draw, drawChild, findChildViewUnder, findContainingItemView, findContainingViewHolder, findViewHolderForAdapterPosition, findViewHolderForItemId, findViewHolderForLayoutPosition, findViewHolderForPosition, fling, focusSearch, generateDefaultLayoutParams, generateLayoutParams, generateLayoutParams, getAccessibilityClassName, getAdapter, getBaseline, getChildAdapterPosition, getChildItemId, getChildLayoutPosition, getChildPosition, getChildViewHolder, getClipToPadding, getCompatAccessibilityDelegate, getDecoratedBoundsWithMargins, getEdgeEffectFactory, getItemAnimator, getItemDecorationAt, getItemDecorationCount, getLayoutManager, getMaxFlingVelocity, getMinFlingVelocity, getOnFlingListener, getPreserveFocusAfterLayout, getRecycledViewPool, getScrollState, hasFixedSize, hasNestedScrollingParent, hasNestedScrollingParent, hasPendingAdapterUpdates, invalidateItemDecorations, isAnimating, isAttachedToWindow, isComputingLayout, isLayoutFrozen, isLayoutSuppressed, isNestedScrollingEnabled, nestedScrollBy, offsetChildrenHorizontal, offsetChildrenVertical, onAttachedToWindow, onChildAttachedToWindow, onChildDetachedFromWindow, onDetachedFromWindow, onDraw, onGenericMotionEvent, onInterceptTouchEvent, onLayout, onMeasure, onRestoreInstanceState, onSaveInstanceState, onScrolled, onScrollStateChanged, onSizeChanged, onTouchEvent, removeDetachedView, removeItemDecoration, removeItemDecorationAt, removeOnChildAttachStateChangeListener, removeOnItemTouchListener, removeOnScrollListener, removeRecyclerListener, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestLayout, scrollBy, scrollTo, sendAccessibilityEventUnchecked, setAccessibilityDelegateCompat, setAdapter, setChildDrawingOrderCallback, setClipToPadding, setEdgeEffectFactory, setHasFixedSize, setItemAnimator, setItemViewCacheSize, setLayoutFrozen, setLayoutTransition, setNestedScrollingEnabled, setOnFlingListener, setOnScrollListener, setPreserveFocusAfterLayout, setRecycledViewPool, setRecyclerListener, setScrollingTouchSlop, setViewCacheExtension, smoothScrollBy, startNestedScroll, startNestedScroll, stopNestedScroll, stopNestedScroll, stopScroll, suppressLayout, swapAdapter
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public VerticalGridView(Context context)

public VerticalGridView(Context context, AttributeSet attrs)

public VerticalGridView(Context context, AttributeSet attrs, int defStyle)

Methods

protected void initAttributes(Context context, AttributeSet attrs)

public void setNumColumns(int numColumns)

Sets the number of columns. Defaults to one.

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.leanback.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.TypedValue;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.RecyclerView;

/**
 * A {@link android.view.ViewGroup} that shows items in a vertically scrolling list. The items
 * come from the {@link RecyclerView.Adapter} associated with this view.
 * <p>
 * {@link RecyclerView.Adapter} can optionally implement {@link FacetProviderAdapter} which
 * provides {@link FacetProvider} for a given view type;  {@link RecyclerView.ViewHolder}
 * can also implement {@link FacetProvider}.  Facet from ViewHolder
 * has a higher priority than the one from FacetProviderAdapter associated with viewType.
 * Supported optional facets are:
 * <ol>
 * <li> {@link ItemAlignmentFacet}
 * When this facet is provided by ViewHolder or FacetProviderAdapter,  it will
 * override the item alignment settings set on VerticalGridView.  This facet also allows multiple
 * alignment positions within one ViewHolder.
 * </li>
 * </ol>
 */
public class VerticalGridView extends BaseGridView {

    public VerticalGridView(@NonNull Context context) {
        this(context, null);
    }

    public VerticalGridView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public VerticalGridView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mLayoutManager.setOrientation(RecyclerView.VERTICAL);
        initAttributes(context, attrs);
    }

    @SuppressLint("CustomViewStyleable")
    protected void initAttributes(@NonNull Context context, @Nullable AttributeSet attrs) {
        initBaseGridViewAttributes(context, attrs);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.lbVerticalGridView);
        ViewCompat.saveAttributeDataForStyleable(
                this, context, R.styleable.lbVerticalGridView, attrs, a, 0, 0);
        setColumnWidth(a);
        setNumColumns(a.getInt(R.styleable.lbVerticalGridView_numberOfColumns, 1));
        a.recycle();
    }

    void setColumnWidth(TypedArray array) {
        TypedValue typedValue = array.peekValue(R.styleable.lbVerticalGridView_columnWidth);
        if (typedValue != null) {
            int size = array.getLayoutDimension(R.styleable.lbVerticalGridView_columnWidth, 0);
            setColumnWidth(size);
        }
    }

    /**
     * Sets the number of columns.  Defaults to one.
     */
    public void setNumColumns(int numColumns) {
        mLayoutManager.setNumRows(numColumns);
        requestLayout();
    }

    /**
     * Sets the column width.
     *
     * @param width May be {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}, or a size
     *              in pixels. If zero, column width will be fixed based on number of columns
     *              and view width.
     */
    public void setColumnWidth(int width) {
        mLayoutManager.setRowHeight(width);
        requestLayout();
    }
}