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


Java RecyclerView.getChildCount方法代碼示例

本文整理匯總了Java中android.support.v7.widget.RecyclerView.getChildCount方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.getChildCount方法的具體用法?Java RecyclerView.getChildCount怎麽用?Java RecyclerView.getChildCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.RecyclerView的用法示例。


在下文中一共展示了RecyclerView.getChildCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onScrolled

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = mLinearLayoutManager.getItemCount();
    firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();

    if (loading) {
        if (totalItemCount > previousTotal) {
            loading = false;
            previousTotal = totalItemCount;
        }
    }
    if (!loading && (totalItemCount - visibleItemCount)
            <= (firstVisibleItem + visibleThreshold)) {
        // End has been reached

        // Do something
        current_page++;

        onLoadMore(current_page);

        loading = true;
    }
}
 
開發者ID:IOSD,項目名稱:YFHR_Android_App,代碼行數:27,代碼來源:EndlessRecyclerOnScrollListener.java

示例2: onScrolled

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = mLinearLayoutManager.getItemCount();
    firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();

    if (loading) {
        if (totalItemCount > previousTotal) {
            loading = false;
            previousTotal = totalItemCount;
        }
    }
    if (!loading
            && (totalItemCount - visibleItemCount) <= firstVisibleItem) {
        currentPage++;
        onLoadMore(currentPage);
        loading = true;
    }
}
 
開發者ID:ChenTianSaber,項目名稱:DailyZhiHu,代碼行數:22,代碼來源:EndLessOnScrollListener.java

示例3: onDrawOver

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        int top = child.getBottom() + params.bottomMargin;
        int bottom = top + mDivider.getIntrinsicHeight();

        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:DialogUIDividerItemDecoration.java

示例4: 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,代碼行數:19,代碼來源:DividerGridItemDecoration.java

示例5: drawHorizontalLine

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void drawHorizontalLine(Canvas c, RecyclerView parent, RecyclerView.State state){
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++){
        final View child = parent.getChildAt(i);

        //獲得child的布局信息
        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);
        //Log.d("wnw", left + " " + top + " "+right+"   "+bottom+" "+i);
    }
}
 
開發者ID:fergus825,項目名稱:SmartOrnament,代碼行數:17,代碼來源:MyDecoration.java

示例6: 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

示例7: 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;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
開發者ID:pooi,項目名稱:Nearby,代碼行數:16,代碼來源:DividerItemDecoration.java

示例8: onDraw

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int childCount = parent.getChildCount();//獲取到子View的個數
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    for (int i = 0; i < childCount - 1; i++) {
        View view = parent.getChildAt(i);
        float top = view.getBottom();
        float bottom = view.getBottom() + mDividerHeight;//子View底部添加分割線的高度
        c.drawRect(left, top, right, bottom, mPaint);//繪製
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:MyDividerItemDecoration.java

示例9: 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);
        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:zuoni1018,項目名稱:CoordinatorLayoutExample-master,代碼行數:16,代碼來源:DividerItemDecoration.java

示例10: isChildInCenterY

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
 * @param recyclerView
 * @param view
 * @return
 */
public static boolean isChildInCenterY(@NonNull RecyclerView recyclerView, @NonNull View view) {
    int childCount = recyclerView.getChildCount();
    int[] lvLocationOnScreen = new int[2];
    recyclerView.getLocationOnScreen(lvLocationOnScreen);
    int middleY = lvLocationOnScreen[1] + recyclerView.getHeight() / 2;
    if (childCount > 0) {
        int[] vLocationOnScreen = new int[2];
        view.getLocationOnScreen(vLocationOnScreen);
        if (vLocationOnScreen[1] <= middleY && vLocationOnScreen[1] + view.getHeight() >= middleY) {
            return true;
        }
    }
    return false;
}
 
開發者ID:sanyuzhang,項目名稱:CircularViewPager,代碼行數:20,代碼來源:CircularUtils.java

示例11: drawHorizontal

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void drawHorizontal(Canvas c, RecyclerView parent) {
    int childCount = parent.getChildCount();

    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        int left = child.getLeft() - params.leftMargin;
        int right = child.getRight() + params.rightMargin + mDivider.getIntrinsicWidth();
        int top = child.getPaddingBottom() + params.bottomMargin;
        int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
開發者ID:ymqq,項目名稱:CommonFramework,代碼行數:15,代碼來源:DividerGridItemDecoration.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: onScrolled

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    final int childCount = recyclerView.getChildCount();
    if (childCount > 0) {
        View lastChild = recyclerView.getChildAt(childCount - 1);
        RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
        int lastVisible = recyclerView.getChildAdapterPosition(lastChild);
        if (lastVisible == outerAdapter.getItemCount() - 1 && hasNextPage() && canLoadNextPage()) {
            onLoadNextPage();
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:BoxingBottomSheetFragment.java

示例14: 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);
        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:ceji-longquan,項目名稱:ceji_android,代碼行數:15,代碼來源:DividerItemDecoration.java

示例15: drawHorizontal

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@SuppressLint("NewApi")
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    int top;
    int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    if(mDividerPadding > 0){
        top = top + mDividerPadding;
        bottom = bottom - mDividerPadding;
    }
    mDivider.setColor(mDividerColor);
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        int left = right - mDivider.getIntrinsicWidth();
        if(mHorizontalDividerWidth > 0){
            left = right - mHorizontalDividerWidth;
        }
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
開發者ID:yangjiantao,項目名稱:AndroidUiKit,代碼行數:35,代碼來源:IDividerItemDecoration.java


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