Java Code Examples for android.support.v7.widget.LinearLayoutManager#getOrientation()
The following examples show how to use
android.support.v7.widget.LinearLayoutManager#getOrientation() .
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: BindItemDecoration.java From LazyRecyclerAdapter with MIT License | 6 votes |
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { super.onDraw(c, parent, state); if (dataSize == 0) { return; } if (parent.getLayoutManager() != null) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); //根据布局管理器绘制边框 if (layoutManager instanceof LinearLayoutManager && !(layoutManager instanceof GridLayoutManager)) { //线性的 LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager; if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) { drawLineVertical(c, parent); } else { drawLineHorizontal(c, parent); } } else { if (getOrientation(layoutManager) == OrientationHelper.HORIZONTAL) { drawGridHorizontal(c, parent); } else { drawGridVertical(c, parent); } } } }
Example 2
Source File: ViewToImageUtil.java From ViewToImage with Apache License 2.0 | 6 votes |
/** * RecyclerView转换成bitmap * * @param recyclerView * @return */ public static List<BitmapWithHeight> getWholeRecyclerViewItemsToBitmap(final RecyclerView recyclerView) { List<BitmapWithHeight> list = new ArrayList<>(); if (recyclerView == null || recyclerView.getAdapter() == null) { return list; } if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager(); if (manager.getOrientation() == LinearLayoutManager.VERTICAL) { int count = manager.getItemCount(); LogUtils.w(count + ""); for (int i = 0; i < count; i++) { View childView = manager.findViewByPosition(i); // TODO: 1/25/16 childView不可见部分为null,无法截长图 if (childView != null) { list.add(getSimpleViewToBitmap(childView, recyclerView.getMeasuredWidth())); } } } else { list.add(getSimpleViewToBitmap(recyclerView, recyclerView.getMeasuredWidth())); } } return list; }
Example 3
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 4
Source File: DividerItemDecoration.java From AndroidSchool with Apache License 2.0 | 5 votes |
private int getOrientation(RecyclerView parent) { if (mOrientation == -1) { if (parent.getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager(); mOrientation = layoutManager.getOrientation(); } } return mOrientation; }
Example 5
Source File: BindItemDecoration.java From LazyRecyclerAdapter with MIT License | 5 votes |
/** * 配置linear模式的item rect */ void linearRect(RecyclerView.LayoutManager layoutManager, RecyclerView parent, View view, Rect outRect) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager; int currentPosition = parent.getChildAdapterPosition(view); //去掉header,上下拉item if (currentPosition >= offsetPosition && currentPosition < endDataPosition) { if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) { if (linearLayoutManager.getReverseLayout()) { outRect.left = space; } else { outRect.right = space; } } else { if (linearLayoutManager.getReverseLayout()) { outRect.top = space; } else { outRect.bottom = space; } } } //第一行顶部间隔 if (needFirstTopEdge && currentPosition == offsetPosition && currentPosition != endDataPosition) { if (orientation == LinearLayoutManager.HORIZONTAL) { if (linearLayoutManager.getReverseLayout()) { outRect.right = space; } else { outRect.left = space; } } else { if (linearLayoutManager.getReverseLayout()) { outRect.bottom = space; } else { outRect.top = space; } } } }
Example 6
Source File: DefineActivity.java From SwipeRecyclerView with Apache License 2.0 | 5 votes |
@Override public int onDragFlags(RecyclerView recyclerView, RecyclerView.ViewHolder targetViewHolder) { int adapterPosition = targetViewHolder.getAdapterPosition(); if (adapterPosition == 0) { // 这里让HeaderView不能拖拽。 return OnItemMovementListener.INVALID;// 返回无效的方向。 } // 真实的Position:通过ViewHolder拿到的position都需要减掉HeadView的数量。 int position = adapterPosition - mRecyclerView.getHeaderCount(); // 假如让普通Item的第一个不能拖拽。 if (position == 0) { return OnItemMovementListener.INVALID;// 返回无效的方向。 } RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { // Grid可以上下左右拖拽。 return OnItemMovementListener.LEFT | OnItemMovementListener.UP | OnItemMovementListener.RIGHT | OnItemMovementListener.DOWN; } else if (layoutManager instanceof LinearLayoutManager) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager)layoutManager; // 横向List只能左右拖拽。 if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) { return (OnItemMovementListener.LEFT | OnItemMovementListener.RIGHT); } // 竖向List只能上下拖拽。 else { return OnItemMovementListener.UP | OnItemMovementListener.DOWN; } } return OnItemMovementListener.INVALID;// 返回无效的方向。 }
Example 7
Source File: DividerItemDecoration.java From droidddle with Apache License 2.0 | 5 votes |
private int getOrientation(RecyclerView parent) { if (parent.getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager(); return layoutManager.getOrientation(); } else throw new IllegalStateException("DividerItemDecoration can only be used with a LinearLayoutManager."); }
Example 8
Source File: FolderChooser.java From screenrecorder with GNU Affero General Public License v3.0 | 5 votes |
private void initRecyclerView() { rv.setHasFixedSize(true); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false); rv.setLayoutManager(layoutManager); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), layoutManager.getOrientation()); rv.addItemDecoration(dividerItemDecoration); if (!isDirectoryEmpty()) { adapter = new DirectoryRecyclerAdapter(getContext(), this, directories); rv.setAdapter(adapter); } tv_currentDir.setText(currentDir.getPath()); }
Example 9
Source File: DividerItemDecoration.java From materialup with Apache License 2.0 | 5 votes |
private int getOrientation(RecyclerView parent) { if (parent.getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager(); return layoutManager.getOrientation(); } else throw new IllegalStateException("DividerItemDecoration can only be used with a LinearLayoutManager."); }
Example 10
Source File: RecyclerViewTV.java From Android-tv-widget with Apache License 2.0 | 5 votes |
/** * 判断是否为横向布局 */ private boolean isHorizontalLayoutManger() { LayoutManager lm = getLayoutManager(); if (lm != null) { if (lm instanceof LinearLayoutManager) { LinearLayoutManager llm = (LinearLayoutManager) lm; return LinearLayoutManager.HORIZONTAL == llm.getOrientation(); } if (lm instanceof GridLayoutManager) { GridLayoutManager glm = (GridLayoutManager) lm; return GridLayoutManager.HORIZONTAL == glm.getOrientation(); } } return false; }
Example 11
Source File: RecyclerViewTV.java From AndroidTVWidget with Apache License 2.0 | 5 votes |
/** * 判断是否为横向布局 */ private boolean isHorizontalLayoutManger() { LayoutManager lm = getLayoutManager(); if (lm != null) { if (lm instanceof LinearLayoutManager) { LinearLayoutManager llm = (LinearLayoutManager) lm; return LinearLayoutManager.HORIZONTAL == llm.getOrientation(); } if (lm instanceof GridLayoutManager) { GridLayoutManager glm = (GridLayoutManager) lm; return GridLayoutManager.HORIZONTAL == glm.getOrientation(); } } return false; }
Example 12
Source File: MainActivity.java From ReadMoreOption with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RecyclerView recyclerView = (RecyclerView)findViewById(R.id.my_recycler_view); LinearLayoutManager mLayoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(mLayoutManager); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), mLayoutManager.getOrientation()); recyclerView.addItemDecoration(dividerItemDecoration); MyAdapter mAdapter = new MyAdapter(this); recyclerView.setAdapter(mAdapter); // TextView tv = (TextView)findViewById(R.id.tv); // tv.setText(getString(R.string.dummy_text)); // // ReadMoreOption readMoreOption = new ReadMoreOption.Builder(this) // // Optional parameters // .textLength(3, ReadMoreOption.TYPE_LINE) //OR // //.textLength(300, ReadMoreOption.TYPE_CHARACTER) // .moreLabel("MORE") // .lessLabel("LESS") // .moreLabelColor(Color.RED) // .lessLabelColor(Color.BLUE) // .labelUnderLine(true) // .expandAnimation(true) // .build(); // readMoreOption.addReadMoreTo(tv, getString(R.string.dummy_text)); }
Example 13
Source File: AllAudioBookPresenter.java From YAAB with GNU General Public License v3.0 | 5 votes |
public void setRecycler(RecyclerView rv) { LinearLayoutManager lm = new LinearLayoutManager(context); rv.setLayoutManager(lm); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(rv.getContext(), lm.getOrientation()); rv.addItemDecoration(dividerItemDecoration); ArrayList<AudioBook> items = new ArrayList<>(); adapter = new AudioBookAdapter(context, items, this); rv.setAdapter(adapter); interactor.loadAllAudioBooks(); }
Example 14
Source File: FolderChooserPresenter.java From YAAB with GNU General Public License v3.0 | 5 votes |
public void initializeList(RecyclerView rv) { LinearLayoutManager lm = new LinearLayoutManager(context); rv.setLayoutManager(lm); adapter = new FolderChooserAdapter(context, new ArrayList<Folder>(), this); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(rv.getContext(), lm.getOrientation()); rv.addItemDecoration(dividerItemDecoration); rv.setAdapter(adapter); interactor.loadFolders(null); }
Example 15
Source File: DividerItemDecoration.java From QuickReturn with Apache License 2.0 | 5 votes |
private int getOrientation(RecyclerView parent) { if (parent.getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager(); return layoutManager.getOrientation(); } else { throw new IllegalStateException( "DividerItemDecoration can only be used with a LinearLayoutManager."); } }
Example 16
Source File: DividerItemDecoration.java From citra_android with GNU General Public License v3.0 | 5 votes |
private int getOrientation(RecyclerView parent) { if (parent.getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager(); return layoutManager.getOrientation(); } else { throw new IllegalStateException( "DividerItemDecoration can only be used with a LinearLayoutManager."); } }
Example 17
Source File: DragItemRecyclerView.java From fingerpoetry-android with Apache License 2.0 | 4 votes |
private void updateDragPositionAndScroll() { View view = findChildView(mDragItem.getX(), mDragItem.getY()); int newPos = getChildLayoutPosition(view); if (newPos == NO_POSITION) { return; } LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager(); if (shouldChangeItemPosition(newPos)) { if (mDisableReorderWhenDragging) { mAdapter.setDropTargetId(mAdapter.getItemId(newPos)); mAdapter.notifyDataSetChanged(); } else { changePosition = true; int pos = layoutManager.findFirstVisibleItemPosition(); View posView = layoutManager.findViewByPosition(pos); mAdapter.changeItemPosition(mDragItemPosition, newPos); mDragItemPosition = newPos; // Since notifyItemMoved scrolls the list we need to scroll back to where we were after the position change. if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) { int topMargin = ((MarginLayoutParams) posView.getLayoutParams()).topMargin; layoutManager.scrollToPositionWithOffset(pos, posView.getTop() - topMargin); } else { int leftMargin = ((MarginLayoutParams) posView.getLayoutParams()).leftMargin; layoutManager.scrollToPositionWithOffset(pos, posView.getLeft() - leftMargin); } } } boolean lastItemReached = false; boolean firstItemReached = false; int top = mClipToPadding ? getPaddingTop() : 0; int bottom = mClipToPadding ? getHeight() - getPaddingBottom() : getHeight(); int left = mClipToPadding ? getPaddingLeft() : 0; int right = mClipToPadding ? getWidth() - getPaddingRight() : getWidth(); ViewHolder lastChild = findViewHolderForLayoutPosition(mAdapter.getItemCount() - 1); ViewHolder firstChild = findViewHolderForLayoutPosition(0); // Check if first or last item has been reached if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) { if (lastChild != null && lastChild.itemView.getBottom() <= bottom) { lastItemReached = true; } if (firstChild != null && firstChild.itemView.getTop() >= top) { firstItemReached = true; } } else { if (lastChild != null && lastChild.itemView.getRight() <= right) { lastItemReached = true; } if (firstChild != null && firstChild.itemView.getLeft() >= left) { firstItemReached = true; } } // Start auto scroll if at the edge if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) { if (mDragItem.getY() > getHeight() - view.getHeight() / 2 && !lastItemReached) { mAutoScroller.startAutoScroll(AutoScroller.ScrollDirection.UP); } else if (mDragItem.getY() < view.getHeight() / 2 && !firstItemReached) { mAutoScroller.startAutoScroll(AutoScroller.ScrollDirection.DOWN); } else { mAutoScroller.stopAutoScroll(); } } else { if (mDragItem.getX() > getWidth() - view.getWidth() / 2 && !lastItemReached) { mAutoScroller.startAutoScroll(AutoScroller.ScrollDirection.LEFT); } else if (mDragItem.getX() < view.getWidth() / 2 && !firstItemReached) { mAutoScroller.startAutoScroll(AutoScroller.ScrollDirection.RIGHT); } else { mAutoScroller.stopAutoScroll(); } } }
Example 18
Source File: DividerItemDecoration.java From ExpandableRecyclerview-Databinding with Apache License 2.0 | 4 votes |
protected int getOrientation(LinearLayoutManager layoutManager) { if (layoutManager != null) { return layoutManager.getOrientation(); } return -1; }
Example 19
Source File: RecyclerViewTV.java From Android-tv-widget with Apache License 2.0 | 4 votes |
/** * 判断是垂直,还是横向. */ private boolean isVertical() { LinearLayoutManager layout = (LinearLayoutManager) getLayoutManager(); return layout.getOrientation() == LinearLayoutManager.VERTICAL; }
Example 20
Source File: ChatFragment.java From ChatApp with Apache License 2.0 | 4 votes |
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_chat, container, false); String currentUserId = FirebaseAuth.getInstance().getCurrentUser().getUid(); // Initialize Chat Database DatabaseReference chatDatabase = FirebaseDatabase.getInstance().getReference().child("Chat").child(currentUserId); chatDatabase.keepSynced(true); // For offline use // RecyclerView related LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext()); linearLayoutManager.setReverseLayout(true); linearLayoutManager.setStackFromEnd(true); RecyclerView recyclerView = view.findViewById(R.id.chat_recycler); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(linearLayoutManager); DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), linearLayoutManager.getOrientation()); recyclerView.addItemDecoration(mDividerItemDecoration); // Initializing adapter FirebaseRecyclerOptions<Chat> options = new FirebaseRecyclerOptions.Builder<Chat>().setQuery(chatDatabase.orderByChild("timestamp"), Chat.class).build(); adapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(options) { @Override public ChatHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user, parent, false); return new ChatHolder(getActivity(), view, getContext()); } @Override protected void onBindViewHolder(final ChatHolder holder, int position, final Chat model) { final String userid = getRef(position).getKey(); holder.setHolder(userid, model.getMessage(), model.getTimestamp(), model.getSeen()); holder.getView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent chatIntent = new Intent(getContext(), ChatActivity.class); chatIntent.putExtra("userid", userid); startActivity(chatIntent); } }); } @Override public void onDataChanged() { super.onDataChanged(); TextView text = view.findViewById(R.id.f_chat_text); if(adapter.getItemCount() == 0) { text.setVisibility(View.VISIBLE); } else { text.setVisibility(View.GONE); } } }; recyclerView.setAdapter(adapter); return view; }