Java Code Examples for android.support.v7.widget.OrientationHelper#VERTICAL
The following examples show how to use
android.support.v7.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: MarginDelegate.java From recycler-view-margin-decoration with Apache License 2.0 | 6 votes |
void calculateMargin( Rect outRect, int position, int spanCurrent, int itemCount, @IntRange( from = 0, to = 1 ) int orientation, boolean isReverse, boolean isRTL ){ if( orientation == OrientationHelper.VERTICAL ){ outRect.left = spanCurrent * spaceItem / spanCount; outRect.right = spaceItem - ( spanCurrent + 1 ) * spaceItem / spanCount; if( isReverse ){ if( position >= spanCount ) outRect.bottom = spaceItem; }else{ if( position >= spanCount ) outRect.top = spaceItem; } }else if( orientation == OrientationHelper.HORIZONTAL ){ outRect.top = spanCurrent * spaceItem / spanCount; outRect.bottom = spaceItem - ( spanCurrent + 1 ) * spaceItem / spanCount; if( isReverse ){ if( position >= spanCount ) outRect.right = spaceItem; }else{ if( position >= spanCount ) outRect.left = spaceItem; } } }
Example 2
Source File: Demo4Activity.java From RecyclerViewDemo with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerview = (RecyclerView) findViewById(R.id.recyclerview); // recyclerview.setLayoutManager(new GridLayoutManager(this, 3)); // recyclerview.setLayoutManager(new LinearLayoutManager(this, // LinearLayoutManager.VERTICAL, false)); recyclerview.setLayoutManager(new StaggeredGridLayoutManager(2, OrientationHelper.VERTICAL)); Divider divider = new Divider(new ColorDrawable(0xffff0000), OrientationHelper.VERTICAL); //单位:px divider.setMargin(50, 50, 50, 50); divider.setHeight(20); recyclerview.addItemDecoration(divider); recyclerview.setAdapter(new Demo3Adapter(this)); }
Example 3
Source File: DividerDecoration.java From fangzhuishushenqi with Apache License 2.0 | 5 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); int orientation = 0; int headerCount = 0,footerCount = 0; if (parent.getAdapter() instanceof RecyclerArrayAdapter){ headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount(); footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount(); } RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof StaggeredGridLayoutManager){ orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation(); }else if (layoutManager instanceof GridLayoutManager){ orientation = ((GridLayoutManager) layoutManager).getOrientation(); }else if (layoutManager instanceof LinearLayoutManager){ orientation = ((LinearLayoutManager) layoutManager).getOrientation(); } if (position>=headerCount&&position<parent.getAdapter().getItemCount()-footerCount||mDrawHeaderFooter){ if (orientation == OrientationHelper.VERTICAL){ outRect.bottom = mHeight; }else { outRect.right = mHeight; } } }
Example 4
Source File: DividerDecoration.java From XFrame with Apache License 2.0 | 5 votes |
/** * 返回条目之间的间隔,例如我们想仿照ListView一样添加分割线,那么就需要设置outRect的下边距。 * @param outRect * @param view * @param parent * @param state */ @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); int orientation = 0; int headerCount = 0,footerCount = 0; if (parent.getAdapter() instanceof XRecyclerViewAdapter){ headerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getHeaderCount(); footerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getFooterCount(); } RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof StaggeredGridLayoutManager){ orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation(); }else if (layoutManager instanceof GridLayoutManager){ orientation = ((GridLayoutManager) layoutManager).getOrientation(); }else if (layoutManager instanceof LinearLayoutManager){ orientation = ((LinearLayoutManager) layoutManager).getOrientation(); } if (position>=headerCount&&position<parent.getAdapter().getItemCount()-footerCount||mDrawHeaderFooter){ if (orientation == OrientationHelper.VERTICAL){ outRect.bottom = mHeight; }else { outRect.right = mHeight; } } }
Example 5
Source File: DividerViewItemLine.java From YCRefreshView with Apache License 2.0 | 5 votes |
/** * 调用的是getItemOffsets会被多次调用,在layoutManager每次测量可摆放的view的时候回调用一次, * 在当前状态下需要摆放多少个view这个方法就会回调多少次。 * @param outRect 核心参数,这个rect相当于item摆放的时候设置的margin, * rect的left相当于item的marginLeft, * rect的right相当于item的marginRight * @param view 当前绘制的view,可以用来获取它在adapter中的位置 * @param parent recyclerView * @param state 状态,用的很少 */ @Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); int orientation = 0; int headerCount = 0,footerCount = 0; if (parent.getAdapter()==null){ return; } //获取header和footer的数量 if (parent.getAdapter() instanceof RecyclerArrayAdapter){ headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount(); footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount(); } RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof StaggeredGridLayoutManager){ orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation(); }else if (layoutManager instanceof GridLayoutManager){ orientation = ((GridLayoutManager) layoutManager).getOrientation(); }else if (layoutManager instanceof LinearLayoutManager){ orientation = ((LinearLayoutManager) layoutManager).getOrientation(); } int itemCount = parent.getAdapter().getItemCount(); int count = itemCount-footerCount; //下面代码才是重点,更多内容可以看我的GitHub博客汇总:https://github.com/yangchong211/YCBlogs if (mDrawHeaderFooter){ if (position >= headerCount && position<count){ if (orientation == OrientationHelper.VERTICAL){ //当是竖直方向的时候,距离底部marginBottom是分割线的高度 outRect.bottom = mHeight; }else { //noinspection SuspiciousNameCombination outRect.right = mHeight; } } } }
Example 6
Source File: DividerDecoration.java From BookReader with Apache License 2.0 | 5 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); int orientation = 0; int headerCount = 0,footerCount = 0; if (parent.getAdapter() instanceof RecyclerArrayAdapter){ headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount(); footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount(); } RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof StaggeredGridLayoutManager){ orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation(); }else if (layoutManager instanceof GridLayoutManager){ orientation = ((GridLayoutManager) layoutManager).getOrientation(); }else if (layoutManager instanceof LinearLayoutManager){ orientation = ((LinearLayoutManager) layoutManager).getOrientation(); } if (position>=headerCount&&position<parent.getAdapter().getItemCount()-footerCount||mDrawHeaderFooter){ if (orientation == OrientationHelper.VERTICAL){ outRect.bottom = mHeight; }else { outRect.right = mHeight; } } }
Example 7
Source File: FamiliarDefaultItemDecoration.java From AndroidBase with Apache License 2.0 | 5 votes |
private void initLayoutManagerType() { this.mLayoutManagerType = mRecyclerViewListener.getCurLayoutManagerType(); RecyclerView.LayoutManager layoutManager = mRecyclerViewListener.getCurLayoutManager(); 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: this.mLayoutManagerType = FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_LINEAR; } initDivisible(); }
Example 8
Source File: FamiliarDefaultItemDecoration.java From AndroidBase with Apache License 2.0 | 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 9
Source File: RecyclerViewFragment.java From COCOFramework with Apache License 2.0 | 4 votes |
protected int orientation() { return OrientationHelper.VERTICAL; }
Example 10
Source File: FamiliarRecyclerView.java From AndroidBase with Apache License 2.0 | 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; } } } } }
Example 11
Source File: FamiliarDefaultItemDecoration.java From AndroidBase with Apache License 2.0 | 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) && !mIsMarginDividersEnabled) { 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 { if (mIsMarginDividersEnabled) { outRect.set(leftOrTopOffset, topOrLeftSize, topOrLeftSize, 0); } 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 { if (mIsMarginDividersEnabled) { outRect.set(topOrLeftSize, topOrLeftSize, rightOrBottomOffset, 0); } 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 12
Source File: FamiliarDefaultItemDecoration.java From AndroidBase with Apache License 2.0 | 4 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 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 13
Source File: BounceRecyclerView.java From weex with Apache License 2.0 | 4 votes |
public BounceRecyclerView(Context context, AttributeSet attrs) { super(context, attrs, OrientationHelper.VERTICAL); }
Example 14
Source File: BaseBounceView.java From weex with Apache License 2.0 | 4 votes |
boolean isVertical(){ return mOrientation==OrientationHelper.VERTICAL; }
Example 15
Source File: BounceRecyclerView.java From weex-uikit with MIT License | 4 votes |
public BounceRecyclerView(Context context, AttributeSet attrs) { super(context, attrs, OrientationHelper.VERTICAL); }
Example 16
Source File: BaseBounceView.java From weex-uikit with MIT License | 4 votes |
boolean isVertical(){ return mOrientation==OrientationHelper.VERTICAL; }
Example 17
Source File: BaseBounceView.java From ucar-weex-core with Apache License 2.0 | 4 votes |
boolean isVertical(){ return mOrientation==OrientationHelper.VERTICAL; }