當前位置: 首頁>>代碼示例>>Java>>正文


Java RecyclerView.getChildAt方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:SupportGridItemDecoration.java

示例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);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:XRecyclerView.java

示例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);
  }
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:17,代碼來源:DividerDecoration.java

示例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);
    }
}
 
開發者ID:Genius,項目名稱:genius-groupie,代碼行數:17,代碼來源:CarouselItemDecoration.java

示例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);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:DividerItemDecoration.java

示例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);
    }
}
 
開發者ID:BittleDragon,項目名稱:MyRepository,代碼行數:17,代碼來源:DividerItemDecoration.java

示例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);


}
 
開發者ID:android-notes,項目名稱:multityperecyclerview,代碼行數:27,代碼來源:RecyclerViewDivider.java

示例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);
        }
}
 
開發者ID:HelloChenJinJun,項目名稱:TestChat,代碼行數:16,代碼來源:ListViewDecoration.java

示例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;
        }
    }

}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:40,代碼來源:RecycleViewDivider.java

示例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;
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:37,代碼來源:HeaderShadowDecoration.java

示例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);
    }
}
 
開發者ID:liuke2016,項目名稱:filepicker,代碼行數:16,代碼來源:DividerListItemDecoration.java

示例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;
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:StickyHeaderDecoration.java

示例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;
    }
}
 
開發者ID:Pl4gue,項目名稱:homeworkManager-android,代碼行數:11,代碼來源:DividerItemDecoration.java

示例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;
}
 
開發者ID:liuyuejinqiu,項目名稱:ScaleViewPager,代碼行數:16,代碼來源:ViewUtils.java

示例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);
    }
}
 
開發者ID:androidDaniel,項目名稱:treasure,代碼行數:16,代碼來源:DividerItemDecoration.java


注:本文中的android.support.v7.widget.RecyclerView.getChildAt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。