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

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

源代码1 项目: MiBandDecompiled   文件: SlidingPaneLayout.java
public void draw(Canvas canvas)
{
    super.draw(canvas);
    View view;
    if (getChildCount() > 1)
    {
        view = getChildAt(1);
    } else
    {
        view = null;
    }
    if (view == null || h == null)
    {
        return;
    } else
    {
        int i1 = h.getIntrinsicWidth();
        int j1 = view.getLeft();
        int k1 = view.getTop();
        int l1 = view.getBottom();
        int i2 = j1 - i1;
        h.setBounds(i2, k1, j1, l1);
        h.draw(canvas);
        return;
    }
}
 
源代码2 项目: MaterialDateTimePicker   文件: DayPickerView.java
public @Nullable MonthView getMostVisibleMonth() {
    boolean verticalScroll = mController.getScrollOrientation() == DatePickerDialog.ScrollOrientation.VERTICAL;
    final int maxSize = verticalScroll ? getHeight() : getWidth();
    int maxDisplayedSize = 0;
    int i = 0;
    int size = 0;
    MonthView mostVisibleMonth = null;

    while (size < maxSize) {
        View child = getChildAt(i);
        if (child == null) {
            break;
        }
        size = verticalScroll ? child.getBottom() : child.getRight();
        int endPosition = verticalScroll ? child.getTop() : child.getLeft();
        int displayedSize = Math.min(size, maxSize) - Math.max(0, endPosition);
        if (displayedSize > maxDisplayedSize) {
            mostVisibleMonth = (MonthView) child;
            maxDisplayedSize = displayedSize;
        }
        i++;
    }
    return mostVisibleMonth;
}
 
源代码3 项目: Telegram-FOSS   文件: RecyclerListView.java
@Override
public View findChildViewUnder(float x, float y) {
    final int count = getChildCount();
    for (int a = 0; a < 2; a++) {
        for (int i = count - 1; i >= 0; i--) {
            final View child = getChildAt(i);
            final float translationX = a == 0 ? child.getTranslationX() : 0;
            final float translationY = a == 0 ? child.getTranslationY() : 0;
            if (x >= child.getLeft() + translationX
                    && x <= child.getRight() + translationX
                    && y >= child.getTop() + translationY
                    && y <= child.getBottom() + translationY) {
                return child;
            }
        }
    }
    return null;
}
 
源代码4 项目: letv   文件: AbsHListView.java
protected int computeHorizontalScrollOffset() {
    int firstPosition = this.mFirstPosition;
    int childCount = getChildCount();
    if (firstPosition < 0 || childCount <= 0) {
        return 0;
    }
    if (this.mSmoothScrollbarEnabled) {
        View view = getChildAt(0);
        int left = view.getLeft();
        int width = view.getWidth();
        if (width > 0) {
            return Math.max(((firstPosition * 100) - ((left * 100) / width)) + ((int) (((((float) getScrollX()) / ((float) getWidth())) * ((float) this.mItemCount)) * 100.0f)), 0);
        }
        return 0;
    }
    int index;
    int count = this.mItemCount;
    if (firstPosition == 0) {
        index = 0;
    } else if (firstPosition + childCount == count) {
        index = count;
    } else {
        index = firstPosition + (childCount / 2);
    }
    return (int) (((float) firstPosition) + (((float) childCount) * (((float) index) / ((float) count))));
}
 
源代码5 项目: AndroidUiKit   文件: CommonTabLayout.java
private void calcOffset() {
        final View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
        mCurrentP.left = currentTabView.getLeft();
        mCurrentP.right = currentTabView.getRight();

        final View lastTabView = mTabsContainer.getChildAt(this.mLastTab);
        mLastP.left = lastTabView.getLeft();
        mLastP.right = lastTabView.getRight();

//        Log.d("AAA", "mLastP--->" + mLastP.left + "&" + mLastP.right);
//        Log.d("AAA", "mCurrentP--->" + mCurrentP.left + "&" + mCurrentP.right);
        if (mLastP.left == mCurrentP.left && mLastP.right == mCurrentP.right) {
            invalidate();
        } else {
            mValueAnimator.setObjectValues(mLastP, mCurrentP);
            if (mIndicatorBounceEnable) {
                mValueAnimator.setInterpolator(mInterpolator);
            }

            if (mIndicatorAnimDuration < 0) {
                mIndicatorAnimDuration = mIndicatorBounceEnable ? 500 : 250;
            }
            mValueAnimator.setDuration(mIndicatorAnimDuration);
            mValueAnimator.start();
        }
    }
 
源代码6 项目: AndroidTreeView   文件: TwoDScrollView.java
/**
  * Finds the next focusable component that fits in this View's bounds
  * (excluding fading edges) pretending that this View's top is located at
  * the parameter top.
  *
  * @param topFocus           look for a candidate is the one at the top of the bounds
  *                           if topFocus is true, or at the bottom of the bounds if topFocus is
  *                           false
  * @param top                the top offset of the bounds in which a focusable must be
  *                           found (the fading edge is assumed to start at this position)
  * @param preferredFocusable the View that has highest priority and will be
  *                           returned if it is within my bounds (null is valid)
  * @return the next focusable component in the bounds or null if none can be
  * found
  */
 private View findFocusableViewInMyBounds(final boolean topFocus, final int top, final boolean leftFocus, final int left, View preferredFocusable) {
/*
* The fading edge's transparent side should be considered for focus
* since it's mostly visible, so we divide the actual fading edge length
* by 2.
*/
     final int verticalFadingEdgeLength = getVerticalFadingEdgeLength() / 2;
     final int topWithoutFadingEdge = top + verticalFadingEdgeLength;
     final int bottomWithoutFadingEdge = top + getHeight() - verticalFadingEdgeLength;
     final int horizontalFadingEdgeLength = getHorizontalFadingEdgeLength() / 2;
     final int leftWithoutFadingEdge = left + horizontalFadingEdgeLength;
     final int rightWithoutFadingEdge = left + getWidth() - horizontalFadingEdgeLength;

     if ((preferredFocusable != null)
             && (preferredFocusable.getTop() < bottomWithoutFadingEdge)
             && (preferredFocusable.getBottom() > topWithoutFadingEdge)
             && (preferredFocusable.getLeft() < rightWithoutFadingEdge)
             && (preferredFocusable.getRight() > leftWithoutFadingEdge)) {
         return preferredFocusable;
     }
     return findFocusableViewInBounds(topFocus, topWithoutFadingEdge, bottomWithoutFadingEdge, leftFocus, leftWithoutFadingEdge, rightWithoutFadingEdge);
 }
 
源代码7 项目: KUtils   文件: Utils.java
static int getStart(View v, boolean withoutPadding) {
  if (v == null) {
    return 0;
  }
  if (isLayoutRtl(v)) {
    return (withoutPadding) ? v.getRight() - getPaddingStart(v) : v.getRight();
  } else {
    return (withoutPadding) ? v.getLeft() + getPaddingStart(v) : v.getLeft();
  }
}
 
源代码8 项目: VerticalViewPager   文件: VerticalViewPager.java
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dy Delta scrolled in pixels
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dy.
 */
protected boolean canScroll(View v, boolean checkV, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                    y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                    canScroll(child, true, dy, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    // to vertical scroll inner WebViews for Froyo+
    if (v instanceof ExtendedWebView) {
        return ((ExtendedWebView) v).canScrollVertical(-dy);
    } else {
        return checkV && ViewCompat.canScrollVertically(v, -dy);
    }
}
 
源代码9 项目: LRecyclerView   文件: DividerHelper.java
public static void drawLeftAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) {

        final int top = child.getTop() - params.topMargin;
        final int bottom = child.getBottom() + params.bottomMargin;
        final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth();
        final int right = left + drawable.getIntrinsicWidth();

        drawable.setBounds(left, top, right, bottom);

        drawable.draw(canvas);
    }
 
源代码10 项目: CoreModule   文件: ViewDragHelper.java
/**
 * Find the topmost child under the given point within the parent view's
 * coordinate system. The child order is determined using
 * {@link ViewDragHelper.Callback#getOrderedChildIndex(int)}
 * .
 *
 * @param x X position to test in the parent's coordinate system
 * @param y Y position to test in the parent's coordinate system
 * @return The topmost child view under (x, y) or null if none found.
 */
public View findTopChildUnder(int x, int y) {
    final int childCount = mParentView.getChildCount();
    for (int i = childCount - 1; i >= 0; i--) {
        final View child = mParentView.getChildAt(mCallback.getOrderedChildIndex(i));
        if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop()
                && y < child.getBottom()) {
            return child;
        }
    }
    return null;
}
 
源代码11 项目: SmartTabLayout   文件: Utils.java
static int getStart(View v, boolean withoutPadding) {
  if (v == null) {
    return 0;
  }
  if (isLayoutRtl(v)) {
    return (withoutPadding) ? v.getRight() - getPaddingStart(v) : v.getRight();
  } else {
    return (withoutPadding) ? v.getLeft() + getPaddingStart(v) : v.getLeft();
  }
}
 
源代码12 项目: android-apps   文件: ScrollingTabContainerView.java
public void animateToTab(final int position) {
    final View tabView = mTabLayout.getChildAt(position);
    if (mTabSelector != null) {
        removeCallbacks(mTabSelector);
    }
    mTabSelector = new Runnable() {
        public void run() {
            final int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;
            smoothScrollTo(scrollPos, 0);
            mTabSelector = null;
        }
    };
    post(mTabSelector);
}
 
源代码13 项目: react-native-GPay   文件: TouchTargetHelper.java
/**
 * Returns whether the touch point is within the child View
 * It is transform aware and will invert the transform Matrix to find the true local points
 * This code is taken from {@link ViewGroup#isTransformedTouchPointInView()}
 */
private static boolean isTransformedTouchPointInView(
    float x,
    float y,
    ViewGroup parent,
    View child,
    PointF outLocalPoint) {
  float localX = x + parent.getScrollX() - child.getLeft();
  float localY = y + parent.getScrollY() - child.getTop();
  Matrix matrix = child.getMatrix();
  if (!matrix.isIdentity()) {
    float[] localXY = mMatrixTransformCoords;
    localXY[0] = localX;
    localXY[1] = localY;
    Matrix inverseMatrix = mInverseMatrix;
    matrix.invert(inverseMatrix);
    inverseMatrix.mapPoints(localXY);
    localX = localXY[0];
    localY = localXY[1];
  }
  if (child instanceof ReactHitSlopView && ((ReactHitSlopView) child).getHitSlopRect() != null) {
    Rect hitSlopRect = ((ReactHitSlopView) child).getHitSlopRect();
    if ((localX >= -hitSlopRect.left && localX < (child.getRight() - child.getLeft()) + hitSlopRect.right)
        && (localY >= -hitSlopRect.top && localY < (child.getBottom() - child.getTop()) + hitSlopRect.bottom)) {
      outLocalPoint.set(localX, localY);
      return true;
    }

    return false;
  } else {
    if ((localX >= 0 && localX < (child.getRight() - child.getLeft()))
        && (localY >= 0 && localY < (child.getBottom() - child.getTop()))) {
      outLocalPoint.set(localX, localY);
      return true;
    }

    return false;
  }
}
 
源代码14 项目: LaunchEnr   文件: ViewGroupFocusHelper.java
private void computeLocationRelativeToContainer(View child, Rect outRect) {
    View parent = (View) child.getParent();
    outRect.left += child.getLeft();
    outRect.top += child.getTop();

    if (parent != mContainer) {
        if (parent instanceof PagedView) {
            PagedView page = (PagedView) parent;
            outRect.left -= page.getScrollForPage(page.indexOfChild(child));
        }

        computeLocationRelativeToContainer(parent, outRect);
    }
}
 
源代码15 项目: Conquer   文件: MyTaskAdapter.java
@Override
public boolean onCheckCanStartDrag(TaskViewHolder holder, int position, int x, int y) {
    // x, y --- relative from the itemView's top-left
    final View mContainerView = holder.mContainer;
    final View dragHandleView = holder.mDragHandle;

    final int offsetX = mContainerView.getLeft() + (int) (ViewCompat.getTranslationX(mContainerView) + 0.5f);
    final int offsetY = mContainerView.getTop() + (int) (ViewCompat.getTranslationY(mContainerView) + 0.5f);

    return hitTest(dragHandleView, x - offsetX, y - offsetY);
}
 
private void setTranslation(View page) {
    ViewPager viewPager = (ViewPager) page.getParent();
    int scroll = viewPager.getScrollX() - page.getLeft();
    page.setTranslationX(scroll);
}
 
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = parent.getPaddingTop() +
            mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom = parent.getHeight() - parent.getPaddingBottom() -
            mMarginProvider.dividerBottomMargin(position, parent) + transitionY;

    int dividerSize = getDividerSize(position, parent);
    boolean isReverseLayout = isReverseLayout(parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set left and right position of divider
        if (isReverseLayout) {
            bounds.right = child.getLeft() - params.leftMargin + transitionX;
            bounds.left = bounds.right - dividerSize;
        } else {
            bounds.left = child.getRight() + params.rightMargin + transitionX;
            bounds.right = bounds.left + dividerSize;
        }
    } else {
        // set center point of divider
        int halfSize = dividerSize / 2;
        if (isReverseLayout) {
            bounds.left = child.getLeft() - params.leftMargin - halfSize + transitionX;
        } else {
            bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX;
        }
        bounds.right = bounds.left;
    }

    if (mPositionInsideItem) {
        if (isReverseLayout) {
            bounds.left += dividerSize;
            bounds.right += dividerSize;
        } else {
            bounds.left -= dividerSize;
            bounds.right -= dividerSize;
        }
    }

    return bounds;
}
 
源代码18 项目: AndroidFastScroll   文件: FastScroller.java
private boolean isInView(@NonNull View view, float x, float y) {
    int scrollX = mView.getScrollX();
    int scrollY = mView.getScrollY();
    return x >= view.getLeft() - scrollX && x < view.getRight() - scrollX
            && y >= view.getTop() - scrollY && y < view.getBottom() - scrollY;
}
 
源代码19 项目: recent-images   文件: TwoWayGridView.java
private void correctTooRight(int numRows, int horizontalSpacing, int childCount) {
	if (DEBUG) Log.i(TAG, "correctTooRight() numRows: " + numRows + " horizontalSpacing: " + horizontalSpacing + M_FIRST_POSITION + mFirstPosition);
	if (mFirstPosition == 0 && childCount > 0) {
		// Get the first child ...
		final View firstChild = getChildAt(0);

		// ... and its left edge
		final int firstLeft = firstChild.getLeft();

		// This is left of our drawable area
		final int start = mListPadding.left;

		// This is right of our drawable area
		final int end = (getRight() - getLeft()) - mListPadding.right;

		// This is how far the left edge of the first view is from the left of the
		// drawable area
		int leftOffset = firstLeft - start;
		final View lastChild = getChildAt(childCount - 1);
		final int lastRight = lastChild.getRight();
		final int lastPosition = mFirstPosition + childCount - 1;

		// Make sure we are 1) Too right, and 2) Either there are more columns to right of the
		// last column or the last column is scrolled off the right of the drawable area
		if (leftOffset > 0 && (lastPosition < mItemCount - 1 || lastRight > end))  {
			if (lastPosition == mItemCount - 1 ) {
				// Don't pull the right too far left
				leftOffset = Math.min(leftOffset, lastRight - end);
			}

			// Move everything left
			offsetChildrenLeftAndRight(-leftOffset);
			if (lastPosition < mItemCount - 1) {
				// Fill the gap that was opened to right of the last position with
				// more columns, if possible
				fillRight(lastPosition + (!mStackFromBottom ? 1 : numRows),
						lastChild.getRight() + horizontalSpacing);
				// Close up the remaining gap
				adjustViewsLeftOrRight();
			}
		}
	}
}
 
源代码20 项目: SweetMusicPlayer   文件: ScrollableTabView.java
private void selectTab(int position){
		for(int i=0;i<mContainer.getChildCount();i++)
			mContainer.getChildAt(i).setSelected(i==position);
		

		View selectedTab=mContainer.getChildAt(position);
		
		final int w=selectedTab.getMeasuredWidth();
		final int l=selectedTab.getLeft();
		
		int x=l-this.getWidth()/2+w/2;
		
//		scrollTo(x, this.getScrollY());
	}
 
 方法所在类
 同类方法