android.view.View#setLeft ( )源码实例Demo

下面列出了android.view.View#setLeft ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public void customRequestLayout() {
    int left = getFirstItemLeft();
    int right;
    for (int i = findFirstVisibleItemPosition(); i < findLastVisibleItemPosition() + 1; i++) {

        // Column headers should have been already calculated.
        right = left + getCacheWidth(i);

        View columnHeader = findViewByPosition(i);
        columnHeader.setLeft(left);
        columnHeader.setRight(right);

        layoutDecoratedWithMargins(columnHeader, columnHeader.getLeft(), columnHeader.getTop
                (), columnHeader.getRight(), columnHeader.getBottom());

        // + 1 is for decoration item.
        left = right + 1;
    }
}
 
源代码2 项目: TableView   文件: ColumnHeaderLayoutManager.java
public void customRequestLayout() {
    int left = getFirstItemLeft();
    int right;
    for (int i = findFirstVisibleItemPosition(); i < findLastVisibleItemPosition() + 1; i++) {

        // Column headers should have been already calculated.
        right = left + getCacheWidth(i);

        View columnHeader = findViewByPosition(i);
        columnHeader.setLeft(left);
        columnHeader.setRight(right);

        layoutDecoratedWithMargins(columnHeader, columnHeader.getLeft(), columnHeader.getTop
                (), columnHeader.getRight(), columnHeader.getBottom());

        // + 1 is for decoration item.
        left = right + 1;
    }
}
 
@NonNull
private LayoutParams initParams(@NonNull View view, int left, int top) {
    int[] loc = new int[2];
    getLocationOnScreen(loc);

    final LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    left -= loc[0];
    top -= loc[1];
    layoutParams.leftMargin = left;
    layoutParams.topMargin = top;
    view.setLeft(left);
    view.setTop(top);
    if (view.getMeasuredWidth() != 0) {
        layoutParams.width = view.getMeasuredWidth();
        view.setRight(left + layoutParams.width);
    }
    if (view.getMeasuredHeight() != 0) {
        layoutParams.height = view.getMeasuredHeight();
        view.setBottom(top + layoutParams.height);
    }
    return layoutParams;
}
 
源代码4 项目: scene   文件: SceneViewCompatUtilsApi21.java
@Override
public void setLeftTopRightBottom(View v, int left, int top, int right, int bottom) {
    v.setLeft(left);
    v.setTop(top);
    v.setRight(right);
    v.setBottom(bottom);
}
 
源代码5 项目: scene   文件: ViewOtherAnimationBuilder.java
@Override
        public void set(View object, final Rect value) {
            //todo 优化,用setLeftTopRightBottom反射
//            ViewUtils.setLeftTopRightBottom(object, mLeft, mTop, mRight, mBottom);
            object.setLeft(value.left);
            object.setTop(value.top);
            object.setRight(value.right);
            object.setBottom(value.bottom);
        }
 
private void layout(View header, RecyclerView parent) {
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) header.getLayoutParams();
    int left = parent.getPaddingLeft() + params.leftMargin;
    int top = parent.getPaddingTop() + params.topMargin;
    header.setLeft(left);
    header.setRight(left + header.getMeasuredWidth());
    header.setTop(top);
    header.setBottom(top + header.getMeasuredHeight());
}
 
private void fit2(int xPosition, int yPosition, int columnCachedWidth, View column,
                  ColumnLayoutManager childLayoutManager) {
    int cellCacheWidth = getCacheWidth(yPosition, xPosition);
    View cell = childLayoutManager.findViewByPosition(xPosition);

    // Control whether the cell needs to be fitted by column header or not.
    if (cell != null) {

        if (cellCacheWidth != columnCachedWidth || mNeedSetLeft) {

            // This is just for setting width value
            if (cellCacheWidth != columnCachedWidth) {
                cellCacheWidth = columnCachedWidth;
                TableViewUtils.setWidth(cell, cellCacheWidth);

                setCacheWidth(yPosition, xPosition, cellCacheWidth);
            }

            // The left & right values of Column header can be considered. Because this
            // method will be worked
            // after drawing process of main thread.
            if (column.getLeft() != cell.getLeft() || column.getRight() != cell.getRight()) {
                // TODO: + 1 is for decoration item. It should be gotten from a generic
                // method  of layoutManager
                // Set right & left values
                cell.setLeft(column.getLeft());
                cell.setRight(column.getRight() + 1);
                childLayoutManager.layoutDecoratedWithMargins(cell, cell.getLeft(), cell
                        .getTop(), cell.getRight(), cell.getBottom());

                mNeedSetLeft = true;
            }
        }
    }
}
 
源代码8 项目: FancyAccordionView   文件: AnimatorUtils.java
/**
 * Returns an animator that animates the bounds of a single view.
 */
public static Animator getBoundsAnimator(View view, int fromLeft, int fromTop, int fromRight,
                                         int fromBottom, int toLeft, int toTop, int toRight, int toBottom) {
    view.setLeft(fromLeft);
    view.setTop(fromTop);
    view.setRight(fromRight);
    view.setBottom(fromBottom);

    return ObjectAnimator.ofPropertyValuesHolder(view,
            PropertyValuesHolder.ofInt(VIEW_LEFT, toLeft),
            PropertyValuesHolder.ofInt(VIEW_TOP, toTop),
            PropertyValuesHolder.ofInt(VIEW_RIGHT, toRight),
            PropertyValuesHolder.ofInt(VIEW_BOTTOM, toBottom));
}
 
源代码9 项目: TableView   文件: CellLayoutManager.java
private void fit2(int xPosition, int yPosition, int columnCachedWidth, @NonNull View column,
                  @NonNull ColumnLayoutManager childLayoutManager) {
    int cellCacheWidth = getCacheWidth(yPosition, xPosition);
    View cell = childLayoutManager.findViewByPosition(xPosition);

    // Control whether the cell needs to be fitted by column header or not.
    if (cell != null) {

        if (cellCacheWidth != columnCachedWidth || mNeedSetLeft) {

            // This is just for setting width value
            if (cellCacheWidth != columnCachedWidth) {
                cellCacheWidth = columnCachedWidth;
                TableViewUtils.setWidth(cell, cellCacheWidth);

                setCacheWidth(yPosition, xPosition, cellCacheWidth);
            }

            // The left & right values of Column header can be considered. Because this
            // method will be worked
            // after drawing process of main thread.
            if (column.getLeft() != cell.getLeft() || column.getRight() != cell.getRight()) {
                // TODO: + 1 is for decoration item. It should be gotten from a generic
                // method  of layoutManager
                // Set right & left values
                cell.setLeft(column.getLeft());
                cell.setRight(column.getRight() + 1);
                childLayoutManager.layoutDecoratedWithMargins(cell, cell.getLeft(), cell
                        .getTop(), cell.getRight(), cell.getBottom());

                mNeedSetLeft = true;
            }
        }
    }
}
 
源代码10 项目: Snake   文件: Snake.java
private static void resetContentViewForFragment(View root) {
    View contentView = root;

    if (root instanceof SnakeHackLayout) {
        contentView = ((SnakeHackLayout) root).getContentView();
    }

    if (null != contentView) {
        contentView.setLeft(0);

        if (root instanceof SnakeHackLayout) {
            ((SnakeHackLayout) root).resetUI();
        }
    }
}
 
private void setViewBounds(final View view, final int width, final int height)
{
    //TODO make this work for all versions
    view.setLeft(0);
    view.setRight(0);
    view.setRight(width);
    view.setBottom(height);
    final ViewParent parent = view.getParent();
    if (parent != null && ((View) parent).getRight() != 0 && ((View) parent).getBottom() != 0)
    {
        setViewBounds(((View) parent), width, height);
    }
}
 
源代码12 项目: android_9.0.0_r45   文件: FastScroller.java
@Override
public void setValue(View object, int value) {
    object.setLeft(value);
}
 
private int fit(int xPosition, int yPosition, int left, int right, int columnCachedWidth) {
    CellRecyclerView child = (CellRecyclerView) findViewByPosition(yPosition);

    if (child != null) {
        ColumnLayoutManager childLayoutManager = (ColumnLayoutManager) child.getLayoutManager();

        int cellCacheWidth = getCacheWidth(yPosition, xPosition);
        View cell = childLayoutManager.findViewByPosition(xPosition);

        // Control whether the cell needs to be fitted by column header or not.
        if (cell != null) {

            if (cellCacheWidth != columnCachedWidth || mNeedSetLeft) {

                // This is just for setting width value
                if (cellCacheWidth != columnCachedWidth) {
                    cellCacheWidth = columnCachedWidth;
                    TableViewUtils.setWidth(cell, cellCacheWidth);

                    setCacheWidth(yPosition, xPosition, cellCacheWidth);
                }

                // Even if the cached values are same, the left & right value wouldn't change.
                // mNeedSetLeft & the below lines for it.
                if (left != IGNORE_LEFT && cell.getLeft() != left) {

                    // Calculate scroll distance
                    int scrollX = Math.max(cell.getLeft(), left) - Math.min(cell.getLeft(),
                            left);

                    // Update its left
                    cell.setLeft(left);

                    int offset = mHorizontalListener.getScrollPositionOffset();

                    // It shouldn't be scroll horizontally and the problem is gotten just for
                    // first visible item.
                    if (offset > 0 && xPosition == childLayoutManager
                            .findFirstVisibleItemPosition() && mCellRecyclerView
                            .getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {

                        int scrollPosition = mHorizontalListener.getScrollPosition();
                        offset = mHorizontalListener.getScrollPositionOffset() + scrollX;

                        // Update scroll position offset value
                        mHorizontalListener.setScrollPositionOffset(offset);
                        // Scroll considering to the desired value.
                        childLayoutManager.scrollToPositionWithOffset(scrollPosition, offset);
                    }
                }

                if (cell.getWidth() != cellCacheWidth) {
                    if (left != IGNORE_LEFT) {
                        // TODO: + 1 is for decoration item. It should be gotten from a
                        // generic method  of layoutManager
                        // Set right
                        right = cell.getLeft() + cellCacheWidth + 1;
                        cell.setRight(right);

                        childLayoutManager.layoutDecoratedWithMargins(cell, cell.getLeft(),
                                cell.getTop(), cell.getRight(), cell.getBottom());
                    }

                    mNeedSetLeft = true;
                }
            }
        }
    }
    return right;
}
 
源代码14 项目: FancyAccordionView   文件: AnimatorUtils.java
@Override
public void set(View view, Integer left) {
    view.setLeft(left);
}
 
源代码15 项目: TableView   文件: CellLayoutManager.java
private int fit(int xPosition, int yPosition, int left, int right, int columnCachedWidth) {
    CellRecyclerView child = (CellRecyclerView) findViewByPosition(yPosition);

    if (child != null) {
        ColumnLayoutManager childLayoutManager = (ColumnLayoutManager) child.getLayoutManager();

        int cellCacheWidth = getCacheWidth(yPosition, xPosition);
        View cell = childLayoutManager.findViewByPosition(xPosition);

        // Control whether the cell needs to be fitted by column header or not.
        if (cell != null) {

            if (cellCacheWidth != columnCachedWidth || mNeedSetLeft) {

                // This is just for setting width value
                if (cellCacheWidth != columnCachedWidth) {
                    cellCacheWidth = columnCachedWidth;
                    TableViewUtils.setWidth(cell, cellCacheWidth);

                    setCacheWidth(yPosition, xPosition, cellCacheWidth);
                }

                // Even if the cached values are same, the left & right value wouldn't change.
                // mNeedSetLeft & the below lines for it.
                if (left != IGNORE_LEFT && cell.getLeft() != left) {

                    // Calculate scroll distance
                    int scrollX = Math.max(cell.getLeft(), left) - Math.min(cell.getLeft(),
                            left);

                    // Update its left
                    cell.setLeft(left);

                    int offset = mHorizontalListener.getScrollPositionOffset();

                    // It shouldn't be scroll horizontally and the problem is gotten just for
                    // first visible item.
                    if (offset > 0 && xPosition == childLayoutManager
                            .findFirstVisibleItemPosition() && getCellRecyclerViewScrollState() != RecyclerView.SCROLL_STATE_IDLE) {

                        int scrollPosition = mHorizontalListener.getScrollPosition();
                        offset = mHorizontalListener.getScrollPositionOffset() + scrollX;

                        // Update scroll position offset value
                        mHorizontalListener.setScrollPositionOffset(offset);
                        // Scroll considering to the desired value.
                        childLayoutManager.scrollToPositionWithOffset(scrollPosition, offset);
                    }
                }

                if (cell.getWidth() != cellCacheWidth) {
                    if (left != IGNORE_LEFT) {
                        // TODO: + 1 is for decoration item. It should be gotten from a
                        // generic method  of layoutManager
                        // Set right
                        right = cell.getLeft() + cellCacheWidth + 1;
                        cell.setRight(right);

                        childLayoutManager.layoutDecoratedWithMargins(cell, cell.getLeft(),
                                cell.getTop(), cell.getRight(), cell.getBottom());
                    }

                    mNeedSetLeft = true;
                }
            }
        }
    }
    return right;
}
 
源代码16 项目: MVPAndroidBootstrap   文件: AnimatedLinearLayout.java
private Animator prepareBoundsAnimator(View child, ChildBounds bounds) {
    int startLeft = bounds.start.left;
    int startTop = bounds.start.top;
    int startRight = bounds.start.right;
    int startBottom = bounds.start.bottom;

    int endLeft = bounds.end.left;
    int endTop = bounds.end.top;
    int endRight = bounds.end.right;
    int endBottom = bounds.end.bottom;

    int changeCount = 0;

    if (startLeft != endLeft) {
        child.setLeft(startLeft);
        changeCount++;
    }
    if (startTop != endTop) {
        child.setTop(startTop);
        changeCount++;
    }
    if (startRight != endRight) {
        child.setRight(startRight);
        changeCount++;
    }
    if (startBottom != endBottom) {
        child.setBottom(startBottom);
        changeCount++;
    }

    if (changeCount == 0) {
        return null;
    }

    PropertyValuesHolder pvh[] = new PropertyValuesHolder[changeCount];
    int pvhIndex = -1;

    if (startLeft != endLeft) {
        pvh[++pvhIndex] = PropertyValuesHolder.ofInt("left", startLeft, endLeft);
    }
    if (startTop != endTop) {
        pvh[++pvhIndex] = PropertyValuesHolder.ofInt("top", startTop, endTop);
    }
    if (startRight != endRight) {
        pvh[++pvhIndex] = PropertyValuesHolder.ofInt("right", startRight, endRight);
    }
    if (startBottom != endBottom) {
        pvh[++pvhIndex] = PropertyValuesHolder.ofInt("bottom", startBottom, endBottom);
    }

    return ObjectAnimator.ofPropertyValuesHolder(child, pvh);
}
 
源代码17 项目: RxAndroidBootstrap   文件: AnimatedLinearLayout.java
private Animator prepareBoundsAnimator(View child, ChildBounds bounds) {
    int startLeft = bounds.start.left;
    int startTop = bounds.start.top;
    int startRight = bounds.start.right;
    int startBottom = bounds.start.bottom;

    int endLeft = bounds.end.left;
    int endTop = bounds.end.top;
    int endRight = bounds.end.right;
    int endBottom = bounds.end.bottom;

    int changeCount = 0;

    if (startLeft != endLeft) {
        child.setLeft(startLeft);
        changeCount++;
    }
    if (startTop != endTop) {
        child.setTop(startTop);
        changeCount++;
    }
    if (startRight != endRight) {
        child.setRight(startRight);
        changeCount++;
    }
    if (startBottom != endBottom) {
        child.setBottom(startBottom);
        changeCount++;
    }

    if (changeCount == 0) {
        return null;
    }

    PropertyValuesHolder pvh[] = new PropertyValuesHolder[changeCount];
    int pvhIndex = -1;

    if (startLeft != endLeft) {
        pvh[++pvhIndex] = PropertyValuesHolder.ofInt("left", startLeft, endLeft);
    }
    if (startTop != endTop) {
        pvh[++pvhIndex] = PropertyValuesHolder.ofInt("top", startTop, endTop);
    }
    if (startRight != endRight) {
        pvh[++pvhIndex] = PropertyValuesHolder.ofInt("right", startRight, endRight);
    }
    if (startBottom != endBottom) {
        pvh[++pvhIndex] = PropertyValuesHolder.ofInt("bottom", startBottom, endBottom);
    }

    return ObjectAnimator.ofPropertyValuesHolder(child, pvh);
}
 
源代码18 项目: fontster   文件: ViewUtils.java
public static void reveal(Activity activity, View view, View sourceView, int colorRes) {
  if (activity == null || view == null || sourceView == null) return;
  if (isLollipop()) {
    final ViewGroupOverlay groupOverlay =
        (ViewGroupOverlay) activity.getWindow().getDecorView().getOverlay();

    final Rect displayRect = new Rect();
    view.getGlobalVisibleRect(displayRect);

    // Make reveal cover the display and status bar.
    final View revealView = new View(activity);
    revealView.setTop(displayRect.top);
    revealView.setBottom(displayRect.bottom);
    revealView.setLeft(displayRect.left);
    revealView.setRight(displayRect.right);
    revealView.setBackgroundColor(ContextCompat.getColor(activity, colorRes));
    groupOverlay.add(revealView);

    final int[] clearLocation = new int[2];
    sourceView.getLocationInWindow(clearLocation);
    clearLocation[0] += sourceView.getWidth() / 2;
    clearLocation[1] += sourceView.getHeight() / 2;

    final int revealCenterX = clearLocation[0] - revealView.getLeft();
    final int revealCenterY = clearLocation[1] - revealView.getTop();

    final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
    final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
    final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
    final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

    try {
      final Animator revealAnimator =
          ViewAnimationUtils.createCircularReveal(revealView,
              revealCenterX, revealCenterY, 0.0f, revealRadius);
      revealAnimator.setDuration(
          activity.getResources().getInteger(android.R.integer.config_mediumAnimTime));

      final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
      alphaAnimator.setDuration(
          activity.getResources().getInteger(android.R.integer.config_shortAnimTime));
      alphaAnimator.addListener(new AnimatorListenerAdapter() {
        @Override public void onAnimationEnd(Animator animation) {
          super.onAnimationEnd(animation);
          view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.abc_fade_in));
          view.setVisibility(View.VISIBLE);
        }
      });

      final AnimatorSet animatorSet = new AnimatorSet();
      animatorSet.play(revealAnimator).before(alphaAnimator);
      animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
      animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override public void onAnimationEnd(Animator animator) {
          groupOverlay.remove(revealView);
        }
      });

      animatorSet.start();
    } catch (IllegalStateException e) {
      Timber.i("View is detached - not animating");
    }
  } else {
    view.setVisibility(View.VISIBLE);
  }
}
 
 方法所在类
 同类方法