public class

WearableLinearLayoutManager

extends LinearLayoutManager

 java.lang.Object

androidx.recyclerview.widget.RecyclerView.LayoutManager

androidx.recyclerview.widget.LinearLayoutManager

↳androidx.wear.widget.WearableLinearLayoutManager

Gradle dependencies

compile group: 'androidx.wear', name: 'wear', version: '1.4.0-alpha01'

  • groupId: androidx.wear
  • artifactId: wear
  • version: 1.4.0-alpha01

Artifact androidx.wear:wear:1.4.0-alpha01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.wear:wear com.android.support:wear

Androidx class mapping:

androidx.wear.widget.WearableLinearLayoutManager android.support.wear.widget.WearableLinearLayoutManager

Overview

This wear-specific implementation of LinearLayoutManager provides basic offsetting logic for updating child layout. For round devices it offsets the children horizontally to make them appear to travel around a circle. For square devices it aligns them in a straight list. This functionality is provided by the CurvingLayoutCallback which is set when constructing the this class with its default constructor WearableLinearLayoutManager.WearableLinearLayoutManager(Context).

Summary

Fields
from LinearLayoutManagerHORIZONTAL, INVALID_OFFSET, VERTICAL
Constructors
publicWearableLinearLayoutManager(Context context)

Creates a WearableLinearLayoutManager for a vertical list.

publicWearableLinearLayoutManager(Context context, WearableLinearLayoutManager.LayoutCallback layoutCallback)

Creates a WearableLinearLayoutManager for a vertical list.

Methods
public WearableLinearLayoutManager.LayoutCallbackgetLayoutCallback()

public voidonLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)

public intscrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)

public voidsetLayoutCallback(WearableLinearLayoutManager.LayoutCallback layoutCallback)

Set a particular instance of the layout callback for this WearableLinearLayoutManager.

from LinearLayoutManagerassertNotInLayoutOrScroll, calculateExtraLayoutSpace, canScrollHorizontally, canScrollVertically, collectAdjacentPrefetchPositions, collectInitialPrefetchPositions, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScrollVectorForPosition, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, findFirstCompletelyVisibleItemPosition, findFirstVisibleItemPosition, findLastCompletelyVisibleItemPosition, findLastVisibleItemPosition, findViewByPosition, generateDefaultLayoutParams, getExtraLayoutSpace, getInitialPrefetchItemCount, getOrientation, getRecycleChildrenOnDetach, getReverseLayout, getStackFromEnd, isAutoMeasureEnabled, isLayoutReversed, isLayoutRTL, isSmoothScrollbarEnabled, onDetachedFromWindow, onFocusSearchFailed, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onLayoutCompleted, onRestoreInstanceState, onSaveInstanceState, prepareForDrop, scrollHorizontallyBy, scrollToPosition, scrollToPositionWithOffset, setInitialPrefetchItemCount, setOrientation, setRecycleChildrenOnDetach, setReverseLayout, setSmoothScrollbarEnabled, setStackFromEnd, smoothScrollToPosition, supportsPredictiveItemAnimations
from RecyclerView.LayoutManageraddDisappearingView, addDisappearingView, addView, addView, assertInLayoutOrScroll, attachView, attachView, attachView, calculateItemDecorationsForChild, checkLayoutParams, chooseSize, detachAndScrapAttachedViews, detachAndScrapView, detachAndScrapViewAt, detachView, detachViewAt, endAnimation, findContainingItemView, generateLayoutParams, generateLayoutParams, getBaseline, getBottomDecorationHeight, getChildAt, getChildCount, getChildMeasureSpec, getChildMeasureSpec, getClipToPadding, getColumnCountForAccessibility, getDecoratedBottom, getDecoratedBoundsWithMargins, getDecoratedLeft, getDecoratedMeasuredHeight, getDecoratedMeasuredWidth, getDecoratedRight, getDecoratedTop, getFocusedChild, getHeight, getHeightMode, getItemCount, getItemViewType, getLayoutDirection, getLeftDecorationWidth, getMinimumHeight, getMinimumWidth, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getPosition, getProperties, getRightDecorationWidth, getRowCountForAccessibility, getSelectionModeForAccessibility, getTopDecorationHeight, getTransformedBoundingBox, getWidth, getWidthMode, hasFocus, ignoreView, isAttachedToWindow, isFocused, isItemPrefetchEnabled, isLayoutHierarchical, isMeasurementCacheEnabled, isSmoothScrolling, isViewPartiallyVisible, layoutDecorated, layoutDecoratedWithMargins, measureChild, measureChildWithMargins, moveView, offsetChildrenHorizontal, offsetChildrenVertical, onAdapterChanged, onAddFocusables, onAttachedToWindow, onDetachedFromWindow, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfoForItem, onInterceptFocusSearch, onItemsAdded, onItemsChanged, onItemsMoved, onItemsRemoved, onItemsUpdated, onItemsUpdated, onMeasure, onRequestChildFocus, onRequestChildFocus, onScrollStateChanged, performAccessibilityAction, performAccessibilityActionForItem, postOnAnimation, removeAllViews, removeAndRecycleAllViews, removeAndRecycleView, removeAndRecycleViewAt, removeCallbacks, removeDetachedView, removeView, removeViewAt, requestChildRectangleOnScreen, requestChildRectangleOnScreen, requestLayout, requestSimpleAnimationsInNextLayout, setAutoMeasureEnabled, setItemPrefetchEnabled, setMeasuredDimension, setMeasuredDimension, setMeasurementCacheEnabled, startSmoothScroll, stopIgnoringView
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public WearableLinearLayoutManager(Context context, WearableLinearLayoutManager.LayoutCallback layoutCallback)

Creates a WearableLinearLayoutManager for a vertical list.

Parameters:

context: Current context, will be used to access resources.
layoutCallback: Callback to be associated with this WearableLinearLayoutManager

public WearableLinearLayoutManager(Context context)

Creates a WearableLinearLayoutManager for a vertical list.

Parameters:

context: Current context, will be used to access resources.

Methods

public void setLayoutCallback(WearableLinearLayoutManager.LayoutCallback layoutCallback)

Set a particular instance of the layout callback for this WearableLinearLayoutManager. The callback will be called on the Ui thread.

Parameters:

layoutCallback:

Returns:

the current WearableLinearLayoutManager.LayoutCallback associated with this WearableLinearLayoutManager.

public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)

public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)

Source

/*
 * Copyright (C) 2017 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.wear.widget;

import android.content.Context;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * This wear-specific implementation of {@link LinearLayoutManager} provides basic
 * offsetting logic for updating child layout. For round devices it offsets the children
 * horizontally to make them appear to travel around a circle. For square devices it aligns them in
 * a straight list. This functionality is provided by the {@link CurvingLayoutCallback} which is
 * set when constructing the this class with its default constructor
 * {@link #WearableLinearLayoutManager(Context)}.
 */
public class WearableLinearLayoutManager extends LinearLayoutManager {

    @Nullable
    private LayoutCallback mLayoutCallback;

    /**
     * Callback for interacting with layout passes.
     */
    public abstract static class LayoutCallback {
        /**
         * Override this method to implement custom child layout behavior on scroll. It is called
         * at the end of each layout pass of the view (including scrolling) and enables you to
         * modify any property of the child view. Examples include scaling the children based on
         * their distance from the center of the parent, or changing the translation of the children
         * to create an illusion of the path they are moving along.
         *
         * @param child  the current child to be affected.
         * @param parent the {@link RecyclerView} parent that this class is attached to.
         */
        public abstract void onLayoutFinished(View child, RecyclerView parent);
    }

    /**
     * Creates a {@link WearableLinearLayoutManager} for a vertical list.
     *
     * @param context Current context, will be used to access resources.
     * @param layoutCallback Callback to be associated with this {@link WearableLinearLayoutManager}
     */
    public WearableLinearLayoutManager(Context context, LayoutCallback layoutCallback) {
        super(context, VERTICAL, false);
        mLayoutCallback = layoutCallback;
    }

    /**
     * Creates a {@link WearableLinearLayoutManager} for a vertical list.
     *
     * @param context Current context, will be used to access resources.
     */
    public WearableLinearLayoutManager(Context context) {
        this(context, new CurvingLayoutCallback(context));
    }

    /**
     * Set a particular instance of the layout callback for this
     * {@link WearableLinearLayoutManager}. The callback will be called on the Ui thread.
     *
     * @param layoutCallback
     */
    public void setLayoutCallback(@Nullable LayoutCallback layoutCallback) {
        mLayoutCallback = layoutCallback;
    }

    /**
     * @return the current {@link LayoutCallback} associated with this
     * {@link WearableLinearLayoutManager}.
     */
    @Nullable
    public LayoutCallback getLayoutCallback() {
        return mLayoutCallback;
    }

    @Override
    public int scrollVerticallyBy(
            int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
        int scrolled = super.scrollVerticallyBy(dy, recycler, state);

        updateLayout();
        return scrolled;
    }

    @Override
    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
        super.onLayoutChildren(recycler, state);
        if (getChildCount() == 0) {
            return;
        }

        updateLayout();
    }

    private void updateLayout() {
        if (mLayoutCallback == null) {
            return;
        }
        final int childCount = getChildCount();
        for (int count = 0; count < childCount; count++) {
            View child = getChildAt(count);
            mLayoutCallback.onLayoutFinished(child, (WearableRecyclerView) child.getParent());
        }
    }
}