本文整理匯總了Java中android.support.v7.widget.RecyclerView.getChildAt方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.getChildAt方法的具體用法?Java RecyclerView.getChildAt怎麽用?Java RecyclerView.getChildAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.getChildAt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawVertical
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void drawVertical(Canvas c, RecyclerView parent) {
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getTop() - params.topMargin;
final int bottom = child.getBottom() + params.bottomMargin;
final int left = child.getRight() + params.rightMargin;
final int right = left + mDivider.getIntrinsicWidth();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
示例2: drawHorizontalDividers
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Adds dividers to a RecyclerView with a LinearLayoutManager or its
* subclass oriented horizontally.
*
* @param canvas The {@link Canvas} onto which horizontal dividers will be
* drawn
* @param parent The RecyclerView onto which horizontal dividers are being
* added
*/
private void drawHorizontalDividers(Canvas canvas, RecyclerView parent) {
int parentTop = parent.getPaddingTop();
int parentBottom = parent.getHeight() - parent.getPaddingBottom();
int childCount = parent.getChildCount();
for (int i = 0; i < childCount - 1; i++) {
View child = parent.getChildAt(i);
LayoutParams params = (LayoutParams) child.getLayoutParams();
int parentLeft = child.getRight() + params.rightMargin;
int parentRight = parentLeft + mDivider.getIntrinsicWidth();
mDivider.setBounds(parentLeft, parentTop, parentRight, parentBottom);
mDivider.draw(canvas);
}
}
示例3: drawHorizontal
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void drawHorizontal(Canvas c, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int recyclerViewLeft = parent.getPaddingLeft();
final int recyclerViewRight = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int left = Math.max(recyclerViewLeft, child.getRight() + params.rightMargin);
final int right = Math.min(recyclerViewRight, left + mDivider.getIntrinsicWidth());
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
示例4: onDraw
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
int childCount = parent.getChildCount();
RecyclerView.LayoutManager lm = parent.getLayoutManager();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
int right = (int) (lm.getDecoratedRight(child) + child.getTranslationX());
if (i == childCount - 1) {
// Last item
right = Math.max(right, parent.getWidth());
}
// Right border
c.drawRect(child.getRight() + child.getTranslationX(), 0, right, parent.getHeight(), grayBackgroundPaint);
}
}
示例5: drawVertical
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void drawVertical(Canvas c, RecyclerView parent) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
android.support.v7.widget.RecyclerView v = new android.support.v7.widget.RecyclerView(parent.getContext());
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
示例6: drawVertical
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void drawVertical(Canvas c, RecyclerView parent) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
RecyclerView v = new RecyclerView(parent.getContext());
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
示例7: drawVerticalDividerBeforeFirstView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void drawVerticalDividerBeforeFirstView(Canvas canvas, RecyclerView parent) {
View child = parent.getChildAt(0);
if (child == null) {
return;
}
int top = parent.getPaddingTop();
int bottom = parent.getHeight() - parent.getPaddingBottom();
int right;
int left;
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
right = child.getLeft() + layoutParams.leftMargin;
int position = parent.getChildAdapterPosition(child);
if (position == 0) {
left = right - mBeforeHeaderDividerWidth;
} else {
left = right - mItemsDividerWidth;
}
mDividerDrawable.setBounds(left, top, right, bottom);
mDividerDrawable.draw(canvas);
}
示例8: onDrawOver
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
int count = parent.getChildCount();
int left = parent.getPaddingLeft();
int right = parent.getWidth() - parent.getPaddingRight();
View child = null;
for (int i = 0; i < count; i++) {
child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int top = child.getBottom() + params.bottomMargin;
int bottom = top + divider.getIntrinsicHeight();
divider.setBounds(left, top, right, bottom);
divider.draw(c);
}
}
示例9: drawVertical
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* 繪製縱向 item 分割線。上、下、左都是可計算的,右側需要獲取給定的寬度值
* @param canvas
* @param parent
*/
private void drawVertical(Canvas canvas, RecyclerView parent) {
//上邊:到父容器的top內間距位置值
final int top = parent.getPaddingTop();
//下邊:到父容器的bottom內間距位置值
final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom();
final int childSize = parent.getChildCount();
//循環繪製每條分割線
for (int i = 0; i < childSize; i++) {
final View child = parent.getChildAt(i);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
//左邊:具體的某條分割線的左邊以child的(right+rightMargin)位置值
final int left = child.getRight() + layoutParams.rightMargin;
//右邊:根據類型判斷
int right;
switch (drawType){
case USEPAINT://構造方法聲明使用畫筆繪製
//右邊:left加上指定的寬度
right = left + mPaintDividerLength;
if (mPaint != null) {
canvas.drawRect(left, top, right, bottom, mPaint);
}
break;
case USEDRAWABLE://構造方法聲明使用drawable
if (mDrawableDivider != null) {
//右邊:left加上指定的寬度
right = left + mDrawableDivider.getIntrinsicWidth();
mDrawableDivider.setBounds(left, top, right, bottom);
mDrawableDivider.draw(canvas);
}
break;
}
}
}
示例10: onDraw
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
// layout basically just gets drawn on the reserved space on top of the first view
mView.layout(parent.getLeft(), 0, parent.getRight(), mView.getMeasuredHeight());
for (int i = 0; i < parent.getChildCount(); i++) {
View view = parent.getChildAt(i);
if (parent.getChildAdapterPosition(view) == 0) {
c.save();
if (mHorizontal) {
c.clipRect(parent.getLeft(), parent.getTop(), view.getLeft(), parent.getBottom());
final int width = mView.getMeasuredWidth();
final float left = (view.getLeft() - width) * mParallax;
c.translate(left, 0);
mView.draw(c);
if (mShadowSize > 0) {
c.translate(view.getLeft() - left - mShadowSize, 0);
c.drawRect(parent.getLeft(), parent.getTop(), mShadowSize, parent.getBottom(), mShadowPaint);
}
} else {
c.clipRect(parent.getLeft(), parent.getTop(), parent.getRight(), view.getTop());
final int height = mView.getMeasuredHeight();
final float top = (view.getTop() - height) * mParallax;
c.translate(0, top);
mView.draw(c);
if (mShadowSize > 0) {
c.translate(0, view.getTop() - top - mShadowSize);
c.drawRect(parent.getLeft(), parent.getTop(), parent.getRight(), mShadowSize, mShadowPaint);
}
}
c.restore();
break;
}
}
}
示例11: drawVerticalDivider
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void drawVerticalDivider(Canvas c, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int left = child.getRight() + params.rightMargin;
final int right = left + mDivider.getIntrinsicWidth();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
示例12: getHeaderTop
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private int getHeaderTop(RecyclerView parent, View child, View header, int adapterPos, int layoutPos) {
int headerHeight = getHeaderHeightForLayout(header);
int top = ((int) child.getY()) - headerHeight;
if (layoutPos == 0) {
final int count = parent.getChildCount();
final long currentId = mAdapter.getHeaderId(adapterPos);
for (int i = 1; i < count; i++) {
int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(i));
if (adapterPosHere != RecyclerView.NO_POSITION) {
long nextId = mAdapter.getHeaderId(adapterPosHere);
if (nextId != currentId) {
final View next = parent.getChildAt(i);
final int offset = ((int) next.getY()) - (headerHeight + getHeader(parent, adapterPosHere).itemView.getHeight());
if (offset < 0) {
return offset;
} else {
break;
}
}
}
}
top = Math.max(0, top);
}
return top;
}
示例13: onDraw
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
android.view.View last = parent.getChildAt(0);
for (int i = 1; i < parent.getChildCount() - 1; i++) {
mDivider.setBounds(last.getLeft(), last.getBottom(), last.getRight(), last.getBottom() + mDivider.getIntrinsicHeight());
mDivider.draw(c);
android.view.View v = parent.getChildAt(i);
last = v;
}
}
示例14: getCenterYChildPosition
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Get position of center child in Y Axes
*/
public static int getCenterYChildPosition(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
if (childCount > 0) {
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterY(recyclerView, child)) {
return recyclerView.getChildAdapterPosition(child);
}
}
}
return childCount;
}
示例15: drawHorizontal
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void drawHorizontal(Canvas c, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int left = child.getRight() + params.rightMargin +
Math.round(ViewCompat.getTranslationX(child));
final int right = left + getDividerWidth();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}