Java Code Examples for androidx.recyclerview.widget.OrientationHelper#VERTICAL
The following examples show how to use
androidx.recyclerview.widget.OrientationHelper#VERTICAL .
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: ListRecyclerConfiguration.java From litho with Apache License 2.0 | 6 votes |
/** Use {@link #create()} instead. */ @Deprecated public ListRecyclerConfiguration( int orientation, boolean reverseLayout, @SnapMode int snapMode, @Nullable RecyclerBinderConfiguration recyclerBinderConfiguration, @Nullable LinearLayoutInfoFactory linearLayoutInfoFactory) { if (orientation == OrientationHelper.VERTICAL && !(snapMode == SNAP_NONE || snapMode == SNAP_TO_START)) { throw new UnsupportedOperationException( "Only snap to start is implemented for vertical lists"); } mOrientation = orientation; mReverseLayout = reverseLayout; mSnapMode = snapMode; mRecyclerBinderConfiguration = recyclerBinderConfiguration == null ? Builder.RECYCLER_BINDER_CONFIGURATION : recyclerBinderConfiguration; mLinearLayoutInfoFactory = linearLayoutInfoFactory == null ? Builder.LINEAR_LAYOUT_INFO_FACTORY : linearLayoutInfoFactory; }
Example 2
Source File: BrickFragment.java From brickkit-android with Apache License 2.0 | 6 votes |
@Override @CallSuper public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view; if (orientation() == OrientationHelper.VERTICAL) { view = inflater.inflate(R.layout.vertical_fragment_brick, container, false); } else { view = inflater.inflate(R.layout.horizontal_fragment_brick, container, false); } RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); recyclerView.setBackgroundColor(recyclerViewBackground); ((DefaultItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false); dataManager.setRecyclerView(getContext(), recyclerView, orientation(), reverse(), view); return view; }
Example 3
Source File: RecyclerBinderAsyncInitRangeIteratorTest.java From litho with Apache License 2.0 | 5 votes |
private RecyclerBinder getStackedEndRecyclerBinder() { final LinearLayoutManager layoutManager = new LinearLayoutManager( mComponentContext.getAndroidContext(), OrientationHelper.VERTICAL, false); layoutManager.setStackFromEnd(true); when(mLayoutInfo.getLayoutManager()).thenReturn(layoutManager); return mRecyclerBinderBuilder.build(mComponentContext); }
Example 4
Source File: ListRecyclerConfiguration.java From litho with Apache License 2.0 | 5 votes |
private static void validate(ListRecyclerConfiguration configuration) { int snapMode = configuration.getSnapMode(); if (configuration.getOrientation() == OrientationHelper.VERTICAL && !(snapMode == SNAP_NONE || snapMode == SNAP_TO_START)) { throw new UnsupportedOperationException( "Only snap to start is implemented for vertical lists"); } }
Example 5
Source File: GridRecyclerConfiguration.java From litho with Apache License 2.0 | 5 votes |
private static void validate(GridRecyclerConfiguration configuration) { int snapMode = configuration.getSnapMode(); if (configuration.getOrientation() == OrientationHelper.VERTICAL && !(snapMode == SNAP_NONE || snapMode == SnapUtil.SNAP_TO_START)) { throw new UnsupportedOperationException( "Only snap to start is implemented for vertical lists"); } }
Example 6
Source File: BrickDialogFragment.java From brickkit-android with Apache License 2.0 | 5 votes |
@Override @CallSuper public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view; if (orientation() == OrientationHelper.VERTICAL) { view = inflater.inflate(R.layout.vertical_fragment_brick, container, false); } else { view = inflater.inflate(R.layout.horizontal_fragment_brick, container, false); } RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); recyclerView.setBackgroundColor(recyclerViewBackground); dataManager.setRecyclerView(getContext(), recyclerView, orientation(), reverse(), view); return view; }
Example 7
Source File: FlexibleLayoutManager.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
/** * Finds the layout orientation of the RecyclerView, no matter which LayoutManager is in use. * * @return one of {@link OrientationHelper#HORIZONTAL}, {@link OrientationHelper#VERTICAL} * @since 5.0.0-rc2 */ @Override public int getOrientation() { RecyclerView.LayoutManager layoutManager = getLayoutManager(); if (layoutManager instanceof LinearLayoutManager) { return ((LinearLayoutManager) layoutManager).getOrientation(); } else if (layoutManager instanceof StaggeredGridLayoutManager) { return ((StaggeredGridLayoutManager) layoutManager).getOrientation(); } return OrientationHelper.VERTICAL; }
Example 8
Source File: FamiliarDefaultItemDecoration.java From FamiliarRecyclerView with MIT License | 5 votes |
private void initLayoutManagerType() { mLayoutManagerType = mFamiliarRecyclerView.getCurLayoutManagerType(); RecyclerView.LayoutManager layoutManager = mFamiliarRecyclerView.getLayoutManager(); switch (mLayoutManagerType) { case FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_LINEAR: LinearLayoutManager curLinearLayoutManager = (LinearLayoutManager) layoutManager; if (curLinearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) { mOrientation = OrientationHelper.HORIZONTAL; } else { mOrientation = OrientationHelper.VERTICAL; } break; case FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_GRID: GridLayoutManager curGridLayoutManager = (GridLayoutManager) layoutManager; mGridSpanCount = curGridLayoutManager.getSpanCount(); if (curGridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) { mOrientation = OrientationHelper.HORIZONTAL; } else { mOrientation = OrientationHelper.VERTICAL; } break; case FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_STAGGERED_GRID: StaggeredGridLayoutManager curStaggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager; mGridSpanCount = curStaggeredGridLayoutManager.getSpanCount(); if (curStaggeredGridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) { mOrientation = OrientationHelper.HORIZONTAL; } else { mOrientation = OrientationHelper.VERTICAL; } break; default: mLayoutManagerType = FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_LINEAR; } initDivisible(); }
Example 9
Source File: FamiliarDefaultItemDecoration.java From FamiliarRecyclerView with MIT License | 5 votes |
private void initDivisible() { int tempDividerDrawableSize = mOrientation == OrientationHelper.VERTICAL ? mHorizontalDividerDrawableHeight : mVerticalDividerDrawableHeight; if (mGridSpanCount > 0 && tempDividerDrawableSize % mGridSpanCount != 0) { float t1 = (float) tempDividerDrawableSize / mGridSpanCount; mUnDivisibleValue = t1 - (int) t1; isDivisible = false; } else { mUnDivisibleValue = 0; isDivisible = true; } }
Example 10
Source File: GridLayoutInfo.java From litho with Apache License 2.0 | 4 votes |
public GridLayoutInfo(Context context, int spanCount) { this(context, spanCount, OrientationHelper.VERTICAL, false); }
Example 11
Source File: RecyclerBinder.java From litho with Apache License 2.0 | 4 votes |
private Size getInitialMeasuredSize( int parentWidthSpec, int parentHeightSpec, boolean canRemeasure) { final Size out = new Size(); final int scrollDirection = mLayoutInfo.getScrollDirection(); final int measuredWidth; final int measuredHeight; final boolean shouldMeasureItemForSize = shouldMeasureItemForSize(parentWidthSpec, parentHeightSpec, scrollDirection, canRemeasure); switch (scrollDirection) { case OrientationHelper.VERTICAL: measuredHeight = SizeSpec.getSize(parentHeightSpec); if (!shouldMeasureItemForSize) { measuredWidth = SizeSpec.getSize(parentWidthSpec); } else if (mSizeForMeasure != null) { measuredWidth = mSizeForMeasure.width; } else { measuredWidth = 0; } break; case OrientationHelper.HORIZONTAL: default: measuredWidth = SizeSpec.getSize(parentWidthSpec); if (!shouldMeasureItemForSize) { measuredHeight = SizeSpec.getSize(parentHeightSpec); } else if (mSizeForMeasure != null) { measuredHeight = mSizeForMeasure.height; } else { measuredHeight = 0; } break; } out.width = measuredWidth; out.height = measuredHeight; return out; }
Example 12
Source File: LinearLayoutInfo.java From litho with Apache License 2.0 | 4 votes |
@Override public LayoutParams generateDefaultLayoutParams() { return getOrientation() == OrientationHelper.VERTICAL ? new RecyclerView.LayoutParams(MATCH_PARENT, WRAP_CONTENT) : new RecyclerView.LayoutParams(WRAP_CONTENT, MATCH_PARENT); }
Example 13
Source File: RecyclerBinderWrapContentTest.java From litho with Apache License 2.0 | 4 votes |
private RecyclerBinder prepareBinderWithMeasuredChildSize( int widthSpec, int heightSpec, int count, final int orientation, final int childSize, boolean async) { RecyclerBinder recyclerBinder = new RecyclerBinder.Builder() .layoutInfo(new LinearLayoutInfo(mComponentContext, orientation, false)) .wrapContent(true) .build(mComponentContext); Size size = new Size(); recyclerBinder.measure(size, widthSpec, heightSpec, mock(EventHandler.class)); final List<RenderInfo> components = new ArrayList<>(); for (int i = 0; i < count; i++) { final Component component = new InlineLayoutSpec() { @Override protected Component onCreateLayout(ComponentContext c) { TestDrawableComponent.Builder builder = TestDrawableComponent.create(c); if (orientation == OrientationHelper.VERTICAL) { return builder.measuredHeight(childSize).build(); } else { return builder.measuredWidth(childSize).build(); } } }; components.add(ComponentRenderInfo.create().component(component).build()); } if (async) { recyclerBinder.insertRangeAtAsync(0, components); recyclerBinder.notifyChangeSetCompleteAsync(true, NO_OP_CHANGE_SET_COMPLETE_CALLBACK); mLayoutThreadShadowLooper.runToEndOfTasks(); } else { recyclerBinder.insertRangeAt(0, components); recyclerBinder.notifyChangeSetComplete(true, NO_OP_CHANGE_SET_COMPLETE_CALLBACK); } return recyclerBinder; }
Example 14
Source File: FamiliarDefaultItemDecoration.java From FamiliarRecyclerView with MIT License | 4 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (mVerticalDividerDrawableHeight <= 0 && mHorizontalDividerDrawableHeight <= 0) return; RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams(); int position = params.getViewAdapterPosition(); int headersCount; int footerCount; int itemViewCount; FamiliarRecyclerView curFamiliarRecyclerView = null; if (parent instanceof FamiliarRecyclerView) { curFamiliarRecyclerView = (FamiliarRecyclerView) parent; footerCount = curFamiliarRecyclerView.getFooterViewsCount(); headersCount = curFamiliarRecyclerView.getHeaderViewsCount(); itemViewCount = curFamiliarRecyclerView.getAdapter().getItemCount() - headersCount - footerCount; } else { headersCount = 0; footerCount = 0; itemViewCount = parent.getAdapter().getItemCount(); } // intercept filter if (isInterceptFilter(position, headersCount, footerCount, itemViewCount)) return; // set headView or footerView if (isHeadViewPos(headersCount, position)) { // head if (mOrientation == OrientationHelper.HORIZONTAL) { outRect.set(mVerticalDividerDrawableHeight, 0, 0, 0); } else { outRect.set(0, mHorizontalDividerDrawableHeight, 0, 0); } return; } else if (isFooterViewPos(headersCount, footerCount, itemViewCount, position)) { // footer if (mOrientation == OrientationHelper.HORIZONTAL) { outRect.set(mVerticalDividerDrawableHeight, 0, 0, 0); } else { outRect.set(0, mHorizontalDividerDrawableHeight, 0, 0); } return; } else if (isEmptyView(curFamiliarRecyclerView, position, headersCount)) { // emptyView if (isHeaderDividersEnabled && headersCount > 0) { if (mOrientation == OrientationHelper.HORIZONTAL) { outRect.set(mVerticalDividerDrawableHeight, 0, 0, 0); } else { outRect.set(0, mHorizontalDividerDrawableHeight, 0, 0); } } return; } // set itemView if (mLayoutManagerType == FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_GRID || mLayoutManagerType == FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_STAGGERED_GRID) { processGridOffsets(outRect, position, headersCount, view); } else { int topOrLeftSize; if ((!isHeaderDividersEnabled || headersCount == 0) && position - headersCount == 0) { topOrLeftSize = 0; } else { topOrLeftSize = mOrientation == OrientationHelper.VERTICAL ? mHorizontalDividerDrawableHeight : mVerticalDividerDrawableHeight; } if (mOrientation == OrientationHelper.HORIZONTAL) { outRect.set(topOrLeftSize, mItemViewBothSidesMargin, 0, mItemViewBothSidesMargin); } else { outRect.set(mItemViewBothSidesMargin, topOrLeftSize, mItemViewBothSidesMargin, 0); } } }
Example 15
Source File: FamiliarDefaultItemDecoration.java From FamiliarRecyclerView with MIT License | 4 votes |
private void processGridOffsets(Rect outRect, int position, int headersCount, View view) { int curGridNum; if (mLayoutManagerType == FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_GRID) { curGridNum = (position - headersCount) % mGridSpanCount; } else { curGridNum = ((StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams()).getSpanIndex(); } int leftOrTopOffset, rightOrBottomOffset; float mDividerLeftBaseOffset, mDividerRightBaseOffset; final int tempDividerDrawableSize = mOrientation == OrientationHelper.HORIZONTAL ? mHorizontalDividerDrawableHeight : mVerticalDividerDrawableHeight; if (mItemViewBothSidesMargin > 0) { // item view left and right margin mDividerLeftBaseOffset = (float) tempDividerDrawableSize / mGridSpanCount * curGridNum - mItemViewBothSidesMargin * 2 / mGridSpanCount * curGridNum + mItemViewBothSidesMargin; mDividerRightBaseOffset = (float) tempDividerDrawableSize / mGridSpanCount * (mGridSpanCount - (curGridNum + 1)) + mItemViewBothSidesMargin * 2 / mGridSpanCount * (curGridNum + 1) - mItemViewBothSidesMargin; } else { mDividerLeftBaseOffset = (float) tempDividerDrawableSize / mGridSpanCount * curGridNum; mDividerRightBaseOffset = (float) tempDividerDrawableSize / mGridSpanCount * (mGridSpanCount - (curGridNum + 1)); } if (!isDivisible && mUnDivisibleValue > 0) { leftOrTopOffset = Math.round(mDividerLeftBaseOffset - mUnDivisibleValue * (curGridNum + 1)); rightOrBottomOffset = Math.round(mDividerRightBaseOffset + mUnDivisibleValue * (curGridNum + 1)); } else { leftOrTopOffset = (int) mDividerLeftBaseOffset; rightOrBottomOffset = (int) mDividerRightBaseOffset; } int topOrLeftSize; if ((!isHeaderDividersEnabled || headersCount == 0) && isGridItemLayoutFirstRow(position, headersCount)) { topOrLeftSize = 0; } else { topOrLeftSize = mOrientation == OrientationHelper.VERTICAL ? mHorizontalDividerDrawableHeight : mVerticalDividerDrawableHeight; } if (isGridItemLayoutLastColumn(position, headersCount, view)) { // last Column if (mOrientation == OrientationHelper.HORIZONTAL) { outRect.set(topOrLeftSize, leftOrTopOffset, 0, mItemViewBothSidesMargin); } else { outRect.set(leftOrTopOffset, topOrLeftSize, mItemViewBothSidesMargin, 0); } } else if (isGridItemLayoutFirstColumn(position, headersCount, view)) { // first column if (mOrientation == OrientationHelper.HORIZONTAL) { outRect.set(topOrLeftSize, mItemViewBothSidesMargin, 0, rightOrBottomOffset); } else { outRect.set(mItemViewBothSidesMargin, topOrLeftSize, rightOrBottomOffset, 0); } } else { // middle column if (mOrientation == OrientationHelper.HORIZONTAL) { outRect.set(topOrLeftSize, leftOrTopOffset, 0, rightOrBottomOffset); } else { outRect.set(leftOrTopOffset, topOrLeftSize, rightOrBottomOffset, 0); } } }
Example 16
Source File: FamiliarRecyclerView.java From FamiliarRecyclerView with MIT License | 4 votes |
private void processDefDivider(boolean isLinearLayoutManager, int layoutManagerOrientation) { if (!isDefaultItemDecoration) return; if ((null == mVerticalDivider || null == mHorizontalDivider) && null != mDefAllDivider) { if (isLinearLayoutManager) { if (layoutManagerOrientation == OrientationHelper.VERTICAL && null == mHorizontalDivider) { mHorizontalDivider = mDefAllDivider; } else if (layoutManagerOrientation == OrientationHelper.HORIZONTAL && null == mVerticalDivider) { mVerticalDivider = mDefAllDivider; } } else { if (null == mVerticalDivider) { mVerticalDivider = mDefAllDivider; } if (null == mHorizontalDivider) { mHorizontalDivider = mDefAllDivider; } } } if (mVerticalDividerHeight > 0 && mHorizontalDividerHeight > 0) return; if (mDefAllDividerHeight > 0) { if (isLinearLayoutManager) { if (layoutManagerOrientation == OrientationHelper.VERTICAL && mHorizontalDividerHeight <= 0) { mHorizontalDividerHeight = mDefAllDividerHeight; } else if (layoutManagerOrientation == OrientationHelper.HORIZONTAL && mVerticalDividerHeight <= 0) { mVerticalDividerHeight = mDefAllDividerHeight; } } else { if (mVerticalDividerHeight <= 0) { mVerticalDividerHeight = mDefAllDividerHeight; } if (mHorizontalDividerHeight <= 0) { mHorizontalDividerHeight = mDefAllDividerHeight; } } } else { if (isLinearLayoutManager) { if (layoutManagerOrientation == OrientationHelper.VERTICAL && mHorizontalDividerHeight <= 0) { if (null != mHorizontalDivider) { if (mHorizontalDivider.getIntrinsicHeight() > 0) { mHorizontalDividerHeight = mHorizontalDivider.getIntrinsicHeight(); } else { mHorizontalDividerHeight = DEF_DIVIDER_HEIGHT; } } } else if (layoutManagerOrientation == OrientationHelper.HORIZONTAL && mVerticalDividerHeight <= 0) { if (null != mVerticalDivider) { if (mVerticalDivider.getIntrinsicHeight() > 0) { mVerticalDividerHeight = mVerticalDivider.getIntrinsicHeight(); } else { mVerticalDividerHeight = DEF_DIVIDER_HEIGHT; } } } } else { if (mVerticalDividerHeight <= 0 && null != mVerticalDivider) { if (mVerticalDivider.getIntrinsicHeight() > 0) { mVerticalDividerHeight = mVerticalDivider.getIntrinsicHeight(); } else { mVerticalDividerHeight = DEF_DIVIDER_HEIGHT; } } if (mHorizontalDividerHeight <= 0 && null != mHorizontalDivider) { if (mHorizontalDivider.getIntrinsicHeight() > 0) { mHorizontalDividerHeight = mHorizontalDivider.getIntrinsicHeight(); } else { mHorizontalDividerHeight = DEF_DIVIDER_HEIGHT; } } } } }