本文整理汇总了Java中android.support.v7.widget.GridLayoutManager.getOrientation方法的典型用法代码示例。如果您正苦于以下问题:Java GridLayoutManager.getOrientation方法的具体用法?Java GridLayoutManager.getOrientation怎么用?Java GridLayoutManager.getOrientation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.GridLayoutManager
的用法示例。
在下文中一共展示了GridLayoutManager.getOrientation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getItemWidth
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
* 计算每个Item的宽度
*/
public int getItemWidth() {
final LayoutManager layoutManager = getLayoutManager();
int itemWidth = 0;
if (layoutManager instanceof GridLayoutManager) {
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
final int spanCount = gridLayoutManager.getSpanCount();
if (gridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
itemWidth = getRawWidth() / (mItemCount / spanCount);
} else {
itemWidth = getRawWidth() / spanCount;
}
} else if (layoutManager instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
itemWidth = getRawWidth() / mItemCount;
} else {
itemWidth = getRawWidth();
}
}
return itemWidth;
}
示例2: setLayoutManager
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void setLayoutManager(LayoutManager layout) {
super.setLayoutManager(layout);
canpull = true;
if (layout instanceof LinearLayoutManager) {
linearLayoutManager = (LinearLayoutManager) layout;
if (linearLayoutManager.getOrientation() != VERTICAL)
canpull = false;
} else if (layout instanceof GridLayoutManager) {
gridLayoutManager = (GridLayoutManager) layout;
if (gridLayoutManager.getOrientation() != VERTICAL)
canpull = false;
} else if (layout instanceof StaggeredGridLayoutManager) {
staggeredGridLayoutManager = (StaggeredGridLayoutManager) layout;
if (staggeredGridLayoutManager.getOrientation() != VERTICAL)
canpull = false;
}
}
示例3: getItemHeight
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public int getItemHeight() {
final LayoutManager layoutManager = getLayoutManager();
int itemHeight = 0;
if (layoutManager instanceof GridLayoutManager) {
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
final int spanCount = gridLayoutManager.getSpanCount();
if (gridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
itemHeight = getRawHeight() / spanCount;
} else {
itemHeight = getRawHeight() / (mItemCount / spanCount);
}
} else if (layoutManager instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
itemHeight = getRawHeight();
} else {
itemHeight = getRawHeight() / mItemCount;
}
}
return itemHeight;
}
示例4: setLayoutManager
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
* 重写此方法,设置GridLayout的上拉加载更多视图的位置
*
* @param layout
*/
@Override
public void setLayoutManager(LayoutManager layout) {
if (layout instanceof GridLayoutManager) {
final GridLayoutManager externalGridLayoutManager = (GridLayoutManager) layout;
final int spanCount = externalGridLayoutManager.getSpanCount();
int orientation = externalGridLayoutManager.getOrientation();
final GridLayoutManager innerGridLayoutManager = new GridLayoutManager(getContext(), spanCount, orientation, false);
innerGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
int headerViewCount = mInternalAdapter.getHeaderViewCount();
int footViewCount = mInternalAdapter.getFootViewCount();
if (position < headerViewCount) {
return spanCount;
}
int totalItemCount = innerGridLayoutManager.getItemCount();
if (position >= totalItemCount - footViewCount) {
return spanCount;
}
return externalGridLayoutManager.getSpanSizeLookup().getSpanSize(position - headerViewCount);
}
});
super.setLayoutManager(innerGridLayoutManager);
} else {
super.setLayoutManager(layout);
}
}
示例5: isLastRaw
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
* 判断指定位置的Item是否是最后一行
*
* @param parent RecyclerView
* @param position 位置
* @param childCount 条目数
* @return true为最后一行,反之不是
*/
public static boolean isLastRaw(RecyclerView parent, int position, int childCount, View view) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager manager = (GridLayoutManager) layoutManager;
int spanCount = manager.getSpanCount();
int orientation = manager.getOrientation();
if (orientation == LinearLayoutManager.VERTICAL) {
int remainder = childCount % spanCount;
childCount = childCount - remainder - (remainder == 0 ? spanCount : 0);
// 判断方向竖是否是最后一行
if (position >= childCount) {
return true;
}
} else {
// 判断方向横是否是最后一行
if ((position + 1) % spanCount == 0) {
return true;
}
}
}
// else if (layoutManager instanceof StaggeredGridLayoutManager) {
// StaggeredGridLayoutManager manager = (StaggeredGridLayoutManager) layoutManager;
// int orientation = manager.getOrientation();
// int spanCount = manager.getSpanCount();
// if (orientation == StaggeredGridLayoutManager.VERTICAL) {
// childCount = childCount - childCount % spanCount;
// // 判断方向竖是否是最后一行
// if (position >= childCount) {
// return true;
// }
// } else {
// // 判断方向横是否是最后一行
// final StaggeredGridLayoutManager.LayoutParams slp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
// return slp.getSpanIndex() == spanCount - 1;
// }
// }
return false;
}
示例6: offsetsOfGrid
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
* GridLayoutManager 布局, 计算每个Item, 应该留出的空间(用来绘制分割线的空间)
*/
private void offsetsOfGrid(Rect outRect, GridLayoutManager layoutManager, int viewLayoutPosition) {
final int spanCount = layoutManager.getSpanCount();
int itemCount = layoutManager.getItemCount();
int right = 0, bottom = 0;
if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) {
//垂直方向
bottom = (int) mDividerSize;
right = (int) mDividerSize;
if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)/*判断是否是最后一排*/) {
if (drawLastHLine) {
} else {
bottom = 0;
}
}
if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)/*判断是否是最靠右的一排*/) {
if (drawLastVLine) {
} else {
right = 0;
}
}
} else {
//水平方向
bottom = (int) mDividerSize;
right = (int) mDividerSize;
if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)/*判断是否是最后一排*/) {
if (drawLastVLine) {
} else {
right = 0;
}
}
if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)/*判断是否是最靠底部的一排*/) {
if (drawLastHLine) {
} else {
bottom = 0;
}
}
}
outRect.set(0, 0, right, bottom);
}
示例7: drawGrid
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
protected void drawGrid(Canvas c, RecyclerView.LayoutManager manager) {
final GridLayoutManager layoutManager = (GridLayoutManager) manager;
final int spanCount = layoutManager.getSpanCount();
int itemCount = layoutManager.getItemCount();
final int firstItem = layoutManager.findFirstVisibleItemPosition();
for (int i = 0; i < layoutManager.getChildCount(); i++) {
final View view = layoutManager.findViewByPosition(firstItem + i);
if (view != null) {
final RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
final int viewLayoutPosition = layoutParams.getViewLayoutPosition();//布局时当前View的位置
if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) {
//垂直方向
if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)/*判断是否是最后一排*/) {
if (viewLayoutPosition == itemCount - 1 /*最后一个*/) {
if (drawLastVLine) {
drawDrawableV(c, view);
}
if (drawLastHLine) {
drawDrawableH(c, view);
}
} else {
drawDrawableV(c, view);
}
} else {
if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)/*判断是否是最靠右的一排*/) {
drawDrawableH(c, view);
if (drawLastVLine) {
drawDrawableV(c, view);
}
} else {
drawDrawableH(c, view);
drawDrawableV(c, view);
}
}
} else {
//水平方向
if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)) {
if (viewLayoutPosition == itemCount - 1 /*最后一个*/) {
if (drawLastVLine) {
drawDrawableV(c, view);
}
if (drawLastHLine) {
drawDrawableH(c, view);
}
} else {
drawDrawableH(c, view);
}
} else {
if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)) {
drawDrawableV(c, view);
if (drawLastHLine) {
drawDrawableH(c, view);
}
} else {
drawDrawableH(c, view);
drawDrawableV(c, view);
}
}
}
}
}
}