Java Code Examples for androidx.core.view.ViewCompat#offsetLeftAndRight()
The following examples show how to use
androidx.core.view.ViewCompat#offsetLeftAndRight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseSwitchButton.java From switchbutton with MIT License | 6 votes |
/** * 移动手柄view * * @param delta 移动量 */ protected final void moveView(int delta) { if (delta == 0) return; final int current = mViewThumb.getLeft(); final int min = getLeftNormal(); final int max = getLeftChecked(); delta = FTouchHelper.getLegalDelta(current, min, max, delta); if (delta == 0) return; ViewCompat.offsetLeftAndRight(mViewThumb, delta); notifyViewPositionChanged(); }
Example 2
Source File: FloatingActionButton.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Pre-Lollipop we use padding so that the shadow has enough space to be drawn. This method * offsets our layout position so that we're positioned correctly if we're on one of our * parent's edges. */ private void offsetIfNeeded( @NonNull CoordinatorLayout parent, @NonNull FloatingActionButton fab) { final Rect padding = fab.shadowPadding; if (padding != null && padding.centerX() > 0 && padding.centerY() > 0) { final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); int offsetTB = 0; int offsetLR = 0; if (fab.getRight() >= parent.getWidth() - lp.rightMargin) { // If we're on the right edge, shift it the right offsetLR = padding.right; } else if (fab.getLeft() <= lp.leftMargin) { // If we're on the left edge, shift it the left offsetLR = -padding.left; } if (fab.getBottom() >= parent.getHeight() - lp.bottomMargin) { // If we're on the bottom edge, shift it down offsetTB = padding.bottom; } else if (fab.getTop() <= lp.topMargin) { // If we're on the top edge, shift it up offsetTB = -padding.top; } if (offsetTB != 0) { ViewCompat.offsetTopAndBottom(fab, offsetTB); } if (offsetLR != 0) { ViewCompat.offsetLeftAndRight(fab, offsetLR); } } }
Example 3
Source File: ViewOverlayApi14.java From material-components-android with Apache License 2.0 | 5 votes |
public void add(View child) { assertNotDisposed(); if (child.getParent() instanceof ViewGroup) { ViewGroup parent = (ViewGroup) child.getParent(); if (parent != hostView && parent.getParent() != null && ViewCompat.isAttachedToWindow(parent)) { // Moving to different container; figure out how to position child such that // it is in the same location on the screen int[] parentLocation = new int[2]; int[] hostViewLocation = new int[2]; parent.getLocationOnScreen(parentLocation); hostView.getLocationOnScreen(hostViewLocation); ViewCompat.offsetLeftAndRight(child, parentLocation[0] - hostViewLocation[0]); ViewCompat.offsetTopAndBottom(child, parentLocation[1] - hostViewLocation[1]); } parent.removeView(child); // if (parent.getLayoutTransition() != null) { // // LayoutTransition will cause the child to delay removal - cancel it // parent.getLayoutTransition().cancel(LayoutTransition.DISAPPEARING); // } // fail-safe if view is still attached for any reason if (child.getParent() != null) { parent.removeView(child); } } super.addView(child); }
Example 4
Source File: ViewOffsetHelper.java From UIWidget with Apache License 2.0 | 4 votes |
private void updateOffsets() { ViewCompat.offsetTopAndBottom(mView, mOffsetTop - (mView.getTop() - mLayoutTop)); ViewCompat.offsetLeftAndRight(mView, mOffsetLeft - (mView.getLeft() - mLayoutLeft)); }
Example 5
Source File: ViewOffsetHelper.java From material-components-android with Apache License 2.0 | 4 votes |
void applyOffsets() { ViewCompat.offsetTopAndBottom(view, offsetTop - (view.getTop() - layoutTop)); ViewCompat.offsetLeftAndRight(view, offsetLeft - (view.getLeft() - layoutLeft)); }