本文整理汇总了Java中android.support.v7.widget.RecyclerView.LayoutManager类的典型用法代码示例。如果您正苦于以下问题:Java LayoutManager类的具体用法?Java LayoutManager怎么用?Java LayoutManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LayoutManager类属于android.support.v7.widget.RecyclerView包,在下文中一共展示了LayoutManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLastColum
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
int childCount) {
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else {
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
return true;
}
}
return false;
}
示例2: isLastColum
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
int childCount) {
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager manager = ((StaggeredGridLayoutManager) layoutManager);
if (manager.getOrientation() == StaggeredGridLayoutManager.VERTICAL) {
View view = parent.getChildAt(pos);
if (view != null && ((StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams())
.getSpanIndex() == ((StaggeredGridLayoutManager) layoutManager).getSpanCount()) {
// 如果是最后一列,则不需要绘制右边
return true;
}
} else {
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
return true;
}
}
return false;
}
示例3: getSpanCount
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private int getSpanCount(RecyclerView parent)
{
// 列数
int spanCount = -1;
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager)
{
spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
} else if (layoutManager instanceof StaggeredGridLayoutManager)
{
spanCount = ((StaggeredGridLayoutManager) layoutManager)
.getSpanCount();
}
return spanCount;
}
示例4: getSpanCount
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private int getSpanCount(RecyclerView parent)
{
// 列数
int spanCount = -1;
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager)
{
spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
} else if (layoutManager instanceof StaggeredGridLayoutManager)
{
spanCount = ((StaggeredGridLayoutManager) layoutManager)
.getSpanCount();
}
return spanCount;
}
示例5: onCreate
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation_picture);
picturesRv = (RecyclerView) findViewById(R.id.rv_picture);
smartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.smart_refresh_layout_picture);
smartRefreshLayout.setOnRefreshLoadmoreListener(this);
LayoutManager layoutManager = new GridLayoutManager(this,3);
picturesRv.setLayoutManager(layoutManager);
pictureAdapter = new PictureAdapter(pictureList,this);
picturesRv.setAdapter(pictureAdapter);
if(!pictureList.isEmpty()){
smartRefreshLayout.finishLoadmore();
smartRefreshLayout.finishRefresh();
pictureAdapter.notifyDataSetChanged();
}else {
smartRefreshLayout.autoRefresh();
}
}
示例6: onMoved
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
public void onMoved(RecyclerView recyclerView, ViewHolder viewHolder, int fromPos, ViewHolder target, int toPos, int x, int y) {
LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof ViewDropHandler) {
((ViewDropHandler) layoutManager).prepareForDrop(viewHolder.itemView, target.itemView, x, y);
return;
}
if (layoutManager.canScrollHorizontally()) {
if (layoutManager.getDecoratedLeft(target.itemView) <= recyclerView.getPaddingLeft()) {
recyclerView.scrollToPosition(toPos);
}
if (layoutManager.getDecoratedRight(target.itemView) >= recyclerView.getWidth() - recyclerView.getPaddingRight()) {
recyclerView.scrollToPosition(toPos);
}
}
if (layoutManager.canScrollVertically()) {
if (layoutManager.getDecoratedTop(target.itemView) <= recyclerView.getPaddingTop()) {
recyclerView.scrollToPosition(toPos);
}
if (layoutManager.getDecoratedBottom(target.itemView) >= recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
recyclerView.scrollToPosition(toPos);
}
}
}
示例7: findSwipedView
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private ViewHolder findSwipedView(MotionEvent motionEvent) {
LayoutManager lm = this.mRecyclerView.getLayoutManager();
if (this.mActivePointerId == -1) {
return null;
}
int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, this.mActivePointerId);
float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - this.mInitialTouchY;
float absDx = Math.abs(MotionEventCompat.getX(motionEvent, pointerIndex) - this.mInitialTouchX);
float absDy = Math.abs(dy);
if (absDx < ((float) this.mSlop) && absDy < ((float) this.mSlop)) {
return null;
}
if (absDx > absDy && lm.canScrollHorizontally()) {
return null;
}
if (absDy > absDx && lm.canScrollVertically()) {
return null;
}
View child = findChildView(motionEvent);
if (child != null) {
return this.mRecyclerView.getChildViewHolder(child);
}
return null;
}
示例8: setMeasuredDimension
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
public void setMeasuredDimension(Rect childrenBounds, int wSpec, int hSpec) {
int height;
int width;
if (this.mCachedBorders == null) {
super.setMeasuredDimension(childrenBounds, wSpec, hSpec);
}
int horizontalPadding = getPaddingLeft() + getPaddingRight();
int verticalPadding = getPaddingTop() + getPaddingBottom();
if (this.mOrientation == 1) {
height = LayoutManager.chooseSize(hSpec, childrenBounds.height() + verticalPadding, getMinimumHeight());
width = LayoutManager.chooseSize(wSpec, this.mCachedBorders[this.mCachedBorders.length - 1] + horizontalPadding, getMinimumWidth());
} else {
width = LayoutManager.chooseSize(wSpec, childrenBounds.width() + horizontalPadding, getMinimumWidth());
height = LayoutManager.chooseSize(hSpec, this.mCachedBorders[this.mCachedBorders.length - 1] + verticalPadding, getMinimumHeight());
}
setMeasuredDimension(width, height);
}
示例9: isLastColum
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
int childCount) {
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % spanCount == 0)
// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else {
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
return true;
}
}
return false;
}
示例10: isLastRaw
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount,
int childCount) {
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
return true;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
// StaggeredGridLayoutManager 且纵向滚动
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
childCount = childCount - childCount % spanCount;
// 如果是最后一行,则不需要绘制底部
if (pos >= childCount)
return true;
// StaggeredGridLayoutManager 且横向滚动
} else {
// 如果是最后一行,则不需要绘制底部
if ((pos + 1) % spanCount == 0) {
return true;
}
}
}
return false;
}
示例11: isLastColumn
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private boolean isLastColumn(RecyclerView parent, int pos, int spanCount, int childCount) {
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % spanCount == 0) {
// 如果是最后一列,则不需要绘制右边
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
if ((pos + 1) % spanCount == 0) {
// 如果是最后一列,则不需要绘制右边
return true;
}
} else {
childCount = childCount - childCount % spanCount;
if (pos >= childCount) {
// 如果是最后一列,则不需要绘制右边
return true;
}
}
}
return false;
}
示例12: isLastRaw
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
childCount = childCount - childCount % spanCount;
if (pos >= childCount) {
// 如果是最后一行,则不需要绘制底部
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
// StaggeredGridLayoutManager 且纵向滚动
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
childCount = childCount - childCount % spanCount;
// 如果是最后一行,则不需要绘制底部
if (pos >= childCount)
return true;
} else {
// StaggeredGridLayoutManager 且横向滚动
// 如果是最后一行,则不需要绘制底部
if ((pos + 1) % spanCount == 0) {
return true;
}
}
}
return false;
}
示例13: isLastColum
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private boolean isLastColum(RecyclerView parent, int pos, int spanCount, int childCount) {
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % spanCount == 0) {
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
if (((StaggeredGridLayoutManager) layoutManager).getOrientation() == 1) {
if ((pos + 1) % spanCount == 0) {
return true;
}
} else if (pos >= childCount - (childCount % spanCount)) {
return true;
}
}
return false;
}
示例14: isLastRaw
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if (pos >= childCount - (childCount % spanCount)) {
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
if (((StaggeredGridLayoutManager) layoutManager).getOrientation() == 1) {
if (pos >= childCount - (childCount % spanCount)) {
return true;
}
} else if ((pos + 1) % spanCount == 0) {
return true;
}
}
return false;
}
示例15: findSwapTargets
import android.support.v7.widget.RecyclerView.LayoutManager; //导入依赖的package包/类
private List<ViewHolder> findSwapTargets(ViewHolder viewHolder) {
if (this.mSwapTargets == null) {
this.mSwapTargets = new ArrayList();
this.mDistances = new ArrayList();
} else {
this.mSwapTargets.clear();
this.mDistances.clear();
}
int margin = this.mCallback.getBoundingBoxMargin();
int left = Math.round(this.mSelectedStartX + this.mDx) - margin;
int top = Math.round(this.mSelectedStartY + this.mDy) - margin;
int right = (viewHolder.itemView.getWidth() + left) + (margin * 2);
int bottom = (viewHolder.itemView.getHeight() + top) + (margin * 2);
int centerX = (left + right) / 2;
int centerY = (top + bottom) / 2;
LayoutManager lm = this.mRecyclerView.getLayoutManager();
int childCount = lm.getChildCount();
for (int i = 0; i < childCount; i++) {
View other = lm.getChildAt(i);
if (other != viewHolder.itemView && other.getBottom() >= top && other.getTop() <= bottom && other.getRight() >= left && other.getLeft() <= right) {
ViewHolder otherVh = this.mRecyclerView.getChildViewHolder(other);
if (this.mCallback.canDropOver(this.mRecyclerView, this.mSelected, otherVh)) {
int dx = Math.abs(centerX - ((other.getLeft() + other.getRight()) / 2));
int dy = Math.abs(centerY - ((other.getTop() + other.getBottom()) / 2));
int dist = (dx * dx) + (dy * dy);
int pos = 0;
int cnt = this.mSwapTargets.size();
int j = 0;
while (j < cnt && dist > ((Integer) this.mDistances.get(j)).intValue()) {
pos++;
j++;
}
this.mSwapTargets.add(pos, otherVh);
this.mDistances.add(pos, Integer.valueOf(dist));
}
}
}
return this.mSwapTargets;
}