Java Code Examples for androidx.core.view.GravityCompat#getAbsoluteGravity()
The following examples show how to use
androidx.core.view.GravityCompat#getAbsoluteGravity() .
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: FoldDrawerLayout.java From zone-sdk with MIT License | 5 votes |
boolean isDrawerView2(View child) { final int gravity = ((LayoutParams) child.getLayoutParams()).gravity; final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(child)); return (absGravity & (Gravity.LEFT | Gravity.RIGHT)) != 0; }
Example 2
Source File: FlowLayout.java From Carbon with Apache License 2.0 | 5 votes |
private void layoutFlowingViews(int width) { int gravity = GravityCompat.getAbsoluteGravity(this.gravity, ViewCompat.getLayoutDirection(this)); if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) { layoutFlowingViewsRight(width); } else { layoutFlowingViewsLeft(width); } }
Example 3
Source File: SwipeLayout.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
@Override public void addView(View child, int index, ViewGroup.LayoutParams params) { if (child == null) return; int gravity = Gravity.NO_GRAVITY; try { gravity = (Integer) params.getClass().getField("gravity").get(params); } catch (Exception e) { e.printStackTrace(); } if (gravity > 0) { gravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this)); if ((gravity & Gravity.LEFT) == Gravity.LEFT) { mDragEdges.put(DragEdge.Left, child); } if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) { mDragEdges.put(DragEdge.Right, child); } if ((gravity & Gravity.TOP) == Gravity.TOP) { mDragEdges.put(DragEdge.Top, child); } if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) { mDragEdges.put(DragEdge.Bottom, child); } } else { for (Map.Entry<DragEdge, View> entry : mDragEdges.entrySet()) { if (entry.getValue() == null) { //means used the drag_edge attr, the no gravity child should be use set mDragEdges.put(entry.getKey(), child); break; } } } if (child.getParent() == this) { return; } super.addView(child, index, params); }
Example 4
Source File: WindowInsetsFrameLayout.java From earth with GNU General Public License v3.0 | 5 votes |
@SuppressLint("RtlHardcoded") private void computeInsetsWithGravity(View view, Rect insets) { LayoutParams lp = (LayoutParams) view.getLayoutParams(); int gravity = GravityCompat.getAbsoluteGravity( lp.gravity, ViewCompat.getLayoutDirection(view)); if (lp.width != LayoutParams.MATCH_PARENT) { if ((gravity & Gravity.LEFT) != Gravity.LEFT) { insets.left = 0; } if ((gravity & Gravity.RIGHT) != Gravity.RIGHT) { insets.right = 0; } } if (lp.height != LayoutParams.MATCH_PARENT) { if ((gravity & Gravity.TOP) != Gravity.TOP) { insets.top = 0; } if ((gravity & Gravity.BOTTOM) != Gravity.BOTTOM) { insets.bottom = 0; } } }
Example 5
Source File: SmoothRefreshLayout.java From SmoothRefreshLayout with MIT License | 4 votes |
protected void layoutOtherView(View child, int parentRight, int parentBottom) { final int width = child.getMeasuredWidth(); final int height = child.getMeasuredHeight(); int childLeft, childTop; final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int gravity = lp.gravity; final int layoutDirection = ViewCompat.getLayoutDirection(this); final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection); final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: childLeft = (int) (getPaddingLeft() + (parentRight - getPaddingLeft() - width) / 2f + lp.leftMargin - lp.rightMargin); break; case Gravity.RIGHT: childLeft = parentRight - width - lp.rightMargin; break; default: childLeft = getPaddingLeft() + lp.leftMargin; } switch (verticalGravity) { case Gravity.CENTER_VERTICAL: childTop = (int) (getPaddingTop() + (parentBottom - getPaddingTop() - height) / 2f + lp.topMargin - lp.bottomMargin); break; case Gravity.BOTTOM: childTop = parentBottom - height - lp.bottomMargin; break; default: childTop = getPaddingTop() + lp.topMargin; } child.layout(childLeft, childTop, childLeft + width, childTop + height); if (sDebug) { Log.d( TAG, String.format( "onLayout(): child: %d %d %d %d", childLeft, childTop, childLeft + width, childTop + height)); } }
Example 6
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 4 votes |
/** Returns a matcher that matches FloatingActionButtons with the specified gravity. */ public static Matcher<View> withFabContentAreaOnMargins(final int gravity) { return new BoundedMatcher<View, View>(View.class) { private String failedCheckDescription; @Override public void describeTo(final Description description) { description.appendText(failedCheckDescription); } @Override public boolean matchesSafely(final View view) { if (!(view instanceof FloatingActionButton)) { return false; } final FloatingActionButton fab = (FloatingActionButton) view; final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) fab.getLayoutParams(); final ViewGroup parent = (ViewGroup) view.getParent(); final Rect area = new Rect(); fab.getContentRect(area); final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(view)); try { switch (absGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: assertEquals(lp.topMargin, fab.getTop() + area.top); break; case Gravity.BOTTOM: assertEquals(parent.getHeight() - lp.bottomMargin, fab.getTop() + area.bottom); break; } switch (absGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: assertEquals(lp.leftMargin, fab.getLeft() + area.left); break; case Gravity.RIGHT: assertEquals(parent.getWidth() - lp.rightMargin, fab.getLeft() + area.right); break; } return true; } catch (Throwable t) { failedCheckDescription = t.getMessage(); return false; } } }; }
Example 7
Source File: TagTabStrip.java From ProjectX with Apache License 2.0 | 4 votes |
@SuppressLint("RtlHardcoded") private void applyGravity(int itemWidth, int itemHeight) { final int count = mCount; if (count == 0) { mFirstCenterX = 0; mFirstCenterY = 0; mItemCenterOffset = 0; return; } final int padding = mPadding; final float scale = mScale > 1 ? mScale : 1; final int paddingStart = ViewCompat.getPaddingStart(this); final int paddingEnd = ViewCompat.getPaddingEnd(this); final int paddingTop = getPaddingTop(); final int paddingBottom = getPaddingBottom(); final int width = getMeasuredWidth(); final int height = getMeasuredHeight(); final int contentWidth = width - paddingStart - paddingEnd; final int contentHeight = height - paddingTop - paddingBottom; mItemCenterOffset = itemWidth + padding; switch (GravityCompat.getAbsoluteGravity(mGravity, ViewCompat.getLayoutDirection(this))) { case Gravity.LEFT: case Gravity.TOP: case Gravity.LEFT | Gravity.TOP: mFirstCenterX = paddingStart + itemWidth * scale * 0.5f; mFirstCenterY = paddingTop + itemHeight * scale * 0.5f; break; case Gravity.CENTER_HORIZONTAL: case Gravity.CENTER_HORIZONTAL | Gravity.TOP: mFirstCenterX = paddingStart + contentWidth * 0.5f - mItemCenterOffset * (count - 1) * 0.5f; mFirstCenterY = paddingTop + itemHeight * scale * 0.5f; break; case Gravity.RIGHT: case Gravity.RIGHT | Gravity.TOP: mFirstCenterX = width - paddingEnd - itemWidth * scale * 0.5f - mItemCenterOffset * (count - 1); mFirstCenterY = paddingTop + itemHeight * scale * 0.5f; break; case Gravity.CENTER_VERTICAL: case Gravity.CENTER_VERTICAL | Gravity.LEFT: mFirstCenterX = paddingStart + itemWidth * scale * 0.5f; mFirstCenterY = paddingTop + contentHeight * 0.5f; break; default: case Gravity.CENTER: mFirstCenterX = paddingStart + contentWidth * 0.5f - mItemCenterOffset * (count - 1) * 0.5f; mFirstCenterY = paddingTop + contentHeight * 0.5f; break; case Gravity.CENTER_VERTICAL | Gravity.RIGHT: mFirstCenterX = width - paddingEnd - itemWidth * scale * 0.5f - mItemCenterOffset * (count - 1); mFirstCenterY = paddingTop + contentHeight * 0.5f; break; case Gravity.BOTTOM: case Gravity.BOTTOM | Gravity.LEFT: mFirstCenterX = paddingStart + itemWidth * scale * 0.5f; mFirstCenterY = height - paddingBottom - itemHeight * scale * 0.5f; break; case Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM: mFirstCenterX = paddingStart + contentWidth * 0.5f - mItemCenterOffset * (count - 1) * 0.5f; mFirstCenterY = height - paddingBottom - itemHeight * scale * 0.5f; break; case Gravity.RIGHT | Gravity.BOTTOM: mFirstCenterX = width - paddingEnd - itemWidth * scale * 0.5f - mItemCenterOffset * (count - 1); mFirstCenterY = height - paddingBottom - itemHeight * scale * 0.5f; break; // 水平方向上沾满 case Gravity.FILL: mItemCenterOffset = count == 1 ? 0 : (contentWidth - itemWidth * scale) / (count - 1); mFirstCenterX = paddingStart + itemWidth * scale * 0.5f; mFirstCenterY = paddingTop + contentHeight * 0.5f; break; case Gravity.FILL_HORIZONTAL: case Gravity.FILL_HORIZONTAL | Gravity.TOP: mItemCenterOffset = count == 1 ? 0 : (contentWidth - itemWidth * scale) / (count - 1); mFirstCenterX = paddingStart + itemWidth * scale * 0.5f; mFirstCenterY = paddingTop + itemHeight * scale * 0.5f; break; case Gravity.FILL_HORIZONTAL | Gravity.BOTTOM: mItemCenterOffset = count == 1 ? 0 : (contentWidth - itemWidth * scale) / (count - 1); mFirstCenterX = paddingStart + itemWidth * scale * 0.5f; mFirstCenterY = height - paddingBottom - itemHeight * scale * 0.5f; break; } }
Example 8
Source File: AdvanceDrawerLayout.java From Drawer-Behavior with MIT License | 2 votes |
int getDrawerViewAbsoluteGravity(int gravity) { return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this)) & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK; }