本文整理汇总了Java中android.support.v7.widget.RecyclerView.LayoutManager.getChildAt方法的典型用法代码示例。如果您正苦于以下问题:Java LayoutManager.getChildAt方法的具体用法?Java LayoutManager.getChildAt怎么用?Java LayoutManager.getChildAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.RecyclerView.LayoutManager
的用法示例。
在下文中一共展示了LayoutManager.getChildAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}