private static void updateGlowSize(RecyclerView rv, EdgeEffectCompat topGlow) {
    int width = rv.getMeasuredWidth();
    int height = rv.getMeasuredHeight();

    if (getClipToPadding(rv)) {
      width -= rv.getPaddingLeft() - rv.getPaddingRight();
      height -= rv.getPaddingTop() - rv.getPaddingBottom();
    }

    width = Math.max(0, width);
    height = Math.max(0, height);

    topGlow.setSize(width, height);
  }
コード例 #2
0
 /**
  * 绘制纵向 item 分割线
  *
  * @param canvas
  * @param parent
  */
 private void drawVertical(Canvas canvas, RecyclerView parent) {
   final int left = parent.getPaddingLeft();
   final int right = parent.getMeasuredWidth() - parent.getPaddingRight();
   final int childSize = parent.getChildCount();
   // linearLayoutManager.findFirstVisibleItemPosition();
   for (int i = 0; i < childSize; i++) {
     final View child = parent.getChildAt(i);
     RecyclerView.LayoutParams layoutParams =
         (RecyclerView.LayoutParams) child.getLayoutParams();
     final int top = child.getBottom() + layoutParams.bottomMargin;
     final int bottom = top + mItemSize;
     canvas.drawRect(left, top, right, bottom, mPaint);
   }
 }
 @Override
 public void onDrawLoadMore(Canvas c, RecyclerView parent) {
   super.onDrawLoadMore(c, parent);
   mProgress = mProgress + 5;
   if (mProgress == 100) {
     mProgress = 0;
   }
   final int left = parent.getPaddingLeft();
   final int right = parent.getMeasuredWidth() - parent.getPaddingRight();
   final int childSize = parent.getChildCount();
   final View child = parent.getChildAt(childSize - 1);
   RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
   final int top = child.getBottom() + layoutParams.bottomMargin;
   final int bottom = top + getLoadMorePadding() / 2;
   paint.setAntiAlias(true); // 抗锯齿
   paint.setFlags(Paint.ANTI_ALIAS_FLAG); // 增强消除锯齿
   paint.setColor(Color.GRAY); // 画笔为灰色
   paint.setStrokeWidth(10); // 画笔宽度
   paint.setStyle(Paint.Style.STROKE); // 中空
   c.drawCircle(
       (right - left) / 2 - mCircleOffset,
       bottom,
       mCircleSize,
       paint); // 在中心为((right - left)/2,bottom)的地方画个半径为mCircleSize的圆,
   paint.setColor(Color.GREEN); // 设置画笔为绿色
   oval.set(
       (right - left) / 2 - mCircleOffset - mCircleSize,
       bottom - mCircleSize,
       (right - left) / 2 - mCircleOffset + mCircleSize,
       bottom + mCircleSize); // 在Circle小于圈圈大小的地方画圆,这样也就保证了半径为mCircleSize
   c.drawArc(
       oval,
       -90,
       ((float) mProgress / 100) * 360,
       false,
       paint); // 圆弧,第二个参数为:起始角度,第三个为跨的角度,第四个为true的时候是实心,false的时候为空心
   paint.reset(); // 将画笔重置
   paint.setStrokeWidth(3); // 再次设置画笔的宽度
   paint.setTextSize(40); // 设置文字的大小
   paint.setColor(Color.BLACK); // 设置画笔颜色
   c.drawText(getLoadmoreString(), (right - left) / 2, bottom + 10, paint);
 }
コード例 #4
0
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
      super.onScrollStateChanged(recyclerView, newState);

      LinearLayoutManager linearLayoutManager =
          (LinearLayoutManager) recyclerView.getLayoutManager();

      if (mCenterPivot == 0) {
        mCenterPivot = recyclerView.getLeft() + recyclerView.getRight();
      }
      if (!mAutoSet) {

        synchronized (this) {
          if (newState == RecyclerView.SCROLL_STATE_IDLE) {

            View view = linearLayoutManager.findViewByPosition(mPosition);

            mPosition = INITIAL_POSITION;

            if (view == null) {
              view = findCenterView(linearLayoutManager);
            }
            int viewCenter = (view.getLeft() + view.getRight()) / 2;
            int viewWidth = view.getRight() - view.getLeft();

            int scrollNeeded = viewCenter - mCenterPivot;

            if (BuildConfig.DEBUG)
              Log.d(
                  TAG,
                  "viewCentre = "
                      + viewCenter
                      + " viewWidth = "
                      + viewWidth
                      + " scrollNeeded = "
                      + scrollNeeded
                      + " recyclerViewWidth = "
                      + recyclerView.getMeasuredWidth());

            recyclerView.smoothScrollBy(scrollNeeded, 0);

            mCenterHolderPosition = recyclerView.getChildLayoutPosition(view);

            if (BuildConfig.DEBUG)
              Log.d(
                  TAG,
                  "centerHolderPosition = " + mCenterHolderPosition + " mPosition = " + mPosition);

            if (mScrollType == null) {
              mScrollType = SwipeType.SWIPE;
            }

            onCenterItemSnap(
                mCenterHolderPosition, recyclerView.getChildViewHolder(view), mScrollType);

            mScrollType = null;
            mAutoSet = true;
          }
        }
      }
      if (newState == RecyclerView.SCROLL_STATE_DRAGGING
          || newState == RecyclerView.SCROLL_STATE_SETTLING) {
        mAutoSet = false;
      }
    }