本文整理汇总了Java中android.support.v4.view.GravityCompat.getAbsoluteGravity方法的典型用法代码示例。如果您正苦于以下问题:Java GravityCompat.getAbsoluteGravity方法的具体用法?Java GravityCompat.getAbsoluteGravity怎么用?Java GravityCompat.getAbsoluteGravity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.GravityCompat
的用法示例。
在下文中一共展示了GravityCompat.getAbsoluteGravity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDrawerTitle
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
@Nullable
public CharSequence getDrawerTitle(int edgeGravity) {
int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
if (absGravity == 3) {
return this.mTitleLeft;
}
if (absGravity == 5) {
return this.mTitleRight;
}
return null;
}
示例2: addView
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
@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);
}
示例3: findDrawerWithGravity
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
/**
* @param gravity the gravity of the child to return. If specified as a
* relative value, it will be resolved according to the current
* layout direction.
* @return the drawer with the specified gravity
*/
View findDrawerWithGravity(int gravity) {
final int absHorizGravity = GravityCompat.getAbsoluteGravity(
gravity, ViewCompat.getLayoutDirection(this)) & Gravity.HORIZONTAL_GRAVITY_MASK;
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
final int childAbsGravity = getDrawerViewAbsoluteGravity(child);
if ((childAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == absHorizGravity) {
return child;
}
}
return null;
}
示例4: findDrawerWithGravity
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
View findDrawerWithGravity(int gravity) {
int absHorizGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this)) & 7;
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if ((getDrawerViewAbsoluteGravity(child) & 7) == absHorizGravity) {
return child;
}
}
return null;
}
示例5: setDrawerLockMode
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
public void setDrawerLockMode(int lockMode, int edgeGravity) {
int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
switch (edgeGravity) {
case 3:
this.mLockModeLeft = lockMode;
break;
case 5:
this.mLockModeRight = lockMode;
break;
case GravityCompat.START /*8388611*/:
this.mLockModeStart = lockMode;
break;
case GravityCompat.END /*8388613*/:
this.mLockModeEnd = lockMode;
break;
}
if (lockMode != 0) {
(absGravity == 3 ? this.mLeftDragger : this.mRightDragger).cancel();
}
switch (lockMode) {
case 1:
View toClose = findDrawerWithGravity(absGravity);
if (toClose != null) {
closeDrawer(toClose);
return;
}
return;
case 2:
View toOpen = findDrawerWithGravity(absGravity);
if (toOpen != null) {
openDrawer(toOpen);
return;
}
return;
default:
return;
}
}
示例6: isDrawerView
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
boolean isDrawerView(View child) {
int absGravity = GravityCompat.getAbsoluteGravity(((LayoutParams) child.getLayoutParams()).gravity, ViewCompat.getLayoutDirection(child));
if ((absGravity & 3) != 0) {
return true;
}
if ((absGravity & 5) != 0) {
return true;
}
return false;
}
示例7: shouldDodge
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
/**
* Checks whether the view with this LayoutParams should dodge the specified view.
*/
private boolean shouldDodge(View other, int layoutDirection) {
LayoutParams lp = (LayoutParams) other.getLayoutParams();
final int absInset = GravityCompat.getAbsoluteGravity(lp.insetEdge, layoutDirection);
return absInset != Gravity.NO_GRAVITY && (absInset &
GravityCompat.getAbsoluteGravity(dodgeInsetEdges, layoutDirection)) == absInset;
}
示例8: layoutChildWithKeyline
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
private void layoutChildWithKeyline(View child, int keyline, int layoutDirection) {
LayoutParams lp = (LayoutParams) child.getLayoutParams();
int absGravity = GravityCompat.getAbsoluteGravity(resolveKeylineGravity(lp.gravity), layoutDirection);
int hgrav = absGravity & 7;
int vgrav = absGravity & 112;
int width = getWidth();
int height = getHeight();
int childWidth = child.getMeasuredWidth();
int childHeight = child.getMeasuredHeight();
if (layoutDirection == 1) {
keyline = width - keyline;
}
int left = getKeyline(keyline) - childWidth;
int top = 0;
switch (hgrav) {
case 1:
left += childWidth / 2;
break;
case 5:
left += childWidth;
break;
}
switch (vgrav) {
case 16:
top = 0 + (childHeight / 2);
break;
case 80:
top = 0 + childHeight;
break;
}
left = Math.max(getPaddingLeft() + lp.leftMargin, Math.min(left, ((width - getPaddingRight()) - childWidth) - lp.rightMargin));
top = Math.max(getPaddingTop() + lp.topMargin, Math.min(top, ((height - getPaddingBottom()) - childHeight) - lp.bottomMargin));
child.layout(left, top, left + childWidth, top + childHeight);
}
示例9: getDrawerLockMode
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
/**
* Check the lock mode of the drawer with the given gravity.
*
* @param edgeGravity Gravity of the drawer to check
* @return one of {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} or
* {@link #LOCK_MODE_LOCKED_OPEN}.
*/
@LockMode
public int getDrawerLockMode(@EdgeGravity int edgeGravity) {
final int absGravity = GravityCompat.getAbsoluteGravity(
edgeGravity, ViewCompat.getLayoutDirection(this));
if (absGravity == Gravity.LEFT) {
return mLockModeLeft;
} else if (absGravity == Gravity.RIGHT) {
return mLockModeRight;
}
return LOCK_MODE_UNLOCKED;
}
示例10: getDrawerTitle
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
/**
* Returns the title of the drawer with the given gravity.
*
* @param edgeGravity Gravity.LEFT, RIGHT, START or END. Expresses which
* drawer to return the title for.
* @return The title of the drawer, or null if none set.
* @see #setDrawerTitle(int, CharSequence)
*/
@Nullable
public CharSequence getDrawerTitle(@EdgeGravity int edgeGravity) {
final int absGravity = GravityCompat.getAbsoluteGravity(
edgeGravity, ViewCompat.getLayoutDirection(this));
if (absGravity == Gravity.LEFT) {
return mTitleLeft;
} else if (absGravity == Gravity.RIGHT) {
return mTitleRight;
}
return null;
}
示例11: getChildHorizontalGravity
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
private int getChildHorizontalGravity(int gravity) {
int ld = ViewCompat.getLayoutDirection(this);
int hGrav = GravityCompat.getAbsoluteGravity(gravity, ld) & 7;
switch (hGrav) {
case 1:
case 3:
case 5:
return hGrav;
default:
return ld == 1 ? 5 : 3;
}
}
示例12: isDrawerView
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
boolean isDrawerView(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;
}
示例13: onMeasure
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (!(widthMode == 1073741824 && heightMode == 1073741824)) {
if (isInEditMode()) {
if (widthMode != Integer.MIN_VALUE) {
if (widthMode == 0) {
widthSize = 300;
}
}
if (heightMode != Integer.MIN_VALUE) {
if (heightMode == 0) {
heightSize = 300;
}
}
} else {
throw new IllegalArgumentException("DrawerLayout must be measured with MeasureSpec.EXACTLY.");
}
}
setMeasuredDimension(widthSize, heightSize);
boolean applyInsets = this.mLastInsets != null && ViewCompat.getFitsSystemWindows(this);
int layoutDirection = ViewCompat.getLayoutDirection(this);
boolean hasDrawerOnLeftEdge = false;
boolean hasDrawerOnRightEdge = false;
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child.getVisibility() != 8) {
MarginLayoutParams lp = (LayoutParams) child.getLayoutParams();
if (applyInsets) {
int cgrav = GravityCompat.getAbsoluteGravity(lp.gravity, layoutDirection);
if (ViewCompat.getFitsSystemWindows(child)) {
IMPL.dispatchChildInsets(child, this.mLastInsets, cgrav);
} else {
IMPL.applyMarginInsets(lp, this.mLastInsets, cgrav);
}
}
if (isContentView(child)) {
child.measure(MeasureSpec.makeMeasureSpec((widthSize - lp.leftMargin) - lp.rightMargin, 1073741824), MeasureSpec.makeMeasureSpec((heightSize - lp.topMargin) - lp.bottomMargin, 1073741824));
} else if (isDrawerView(child)) {
if (SET_DRAWER_SHADOW_FROM_ELEVATION && ViewCompat.getElevation(child) != this.mDrawerElevation) {
ViewCompat.setElevation(child, this.mDrawerElevation);
}
int childGravity = getDrawerViewAbsoluteGravity(child) & 7;
boolean isLeftEdgeDrawer = childGravity == 3;
if (!(isLeftEdgeDrawer && hasDrawerOnLeftEdge) && (isLeftEdgeDrawer || !hasDrawerOnRightEdge)) {
if (isLeftEdgeDrawer) {
hasDrawerOnLeftEdge = true;
} else {
hasDrawerOnRightEdge = true;
}
child.measure(getChildMeasureSpec(widthMeasureSpec, (this.mMinDrawerMargin + lp.leftMargin) + lp.rightMargin, lp.width), getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin, lp.height));
} else {
throw new IllegalStateException("Child drawer has absolute gravity " + gravityToString(childGravity) + " but this " + TAG + " already has a " + "drawer view along that edge");
}
} else {
throw new IllegalStateException("Child " + child + " at index " + i + " does not have a valid layout_gravity - must be Gravity.LEFT, " + "Gravity.RIGHT or Gravity.NO_GRAVITY");
}
}
}
}
示例14: getDesiredAnchoredChildRectWithoutConstraints
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
private void getDesiredAnchoredChildRectWithoutConstraints(View child, int layoutDirection,
Rect anchorRect, Rect out, LayoutParams lp, int childWidth, int childHeight) {
final int absGravity = GravityCompat.getAbsoluteGravity(
resolveAnchoredChildGravity(lp.gravity), layoutDirection);
final int absAnchorGravity = GravityCompat.getAbsoluteGravity(
resolveGravity(lp.anchorGravity),
layoutDirection);
final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK;
int left;
int top;
// Align to the anchor. This puts us in an assumed right/bottom child view gravity.
// If this is not the case we will subtract out the appropriate portion of
// the child size below.
switch (anchorHgrav) {
default:
case Gravity.LEFT:
left = anchorRect.left;
break;
case Gravity.RIGHT:
left = anchorRect.right;
break;
case Gravity.CENTER_HORIZONTAL:
left = anchorRect.left + anchorRect.width() / 2;
break;
}
switch (anchorVgrav) {
default:
case Gravity.TOP:
top = anchorRect.top;
break;
case Gravity.BOTTOM:
top = anchorRect.bottom;
break;
case Gravity.CENTER_VERTICAL:
top = anchorRect.top + anchorRect.height() / 2;
break;
}
// Offset by the child view's gravity itself. The above assumed right/bottom gravity.
switch (hgrav) {
default:
case Gravity.LEFT:
left -= childWidth;
break;
case Gravity.RIGHT:
// Do nothing, we're already in position.
break;
case Gravity.CENTER_HORIZONTAL:
left -= childWidth / 2;
break;
}
switch (vgrav) {
default:
case Gravity.TOP:
top -= childHeight;
break;
case Gravity.BOTTOM:
// Do nothing, we're already in position.
break;
case Gravity.CENTER_VERTICAL:
top -= childHeight / 2;
break;
}
out.set(left, top, left + childWidth, top + childHeight);
}
示例15: layoutChildWithKeyline
import android.support.v4.view.GravityCompat; //导入方法依赖的package包/类
/**
* Lay out a child view with respect to a keyline.
*
* <p>The keyline represents a horizontal offset from the unpadded starting edge of
* the CoordinatorLayout. The child's gravity will affect how it is positioned with
* respect to the keyline.</p>
*
* @param child child to lay out
* @param keyline offset from the starting edge in pixels of the keyline to align with
* @param layoutDirection ViewCompat constant for layout direction
*/
private void layoutChildWithKeyline(View child, int keyline, int layoutDirection) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int absGravity = GravityCompat.getAbsoluteGravity(
resolveKeylineGravity(lp.gravity), layoutDirection);
final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
final int width = getWidth();
final int height = getHeight();
final int childWidth = child.getMeasuredWidth();
final int childHeight = child.getMeasuredHeight();
if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) {
keyline = width - keyline;
}
int left = getKeyline(keyline) - childWidth;
int top = 0;
switch (hgrav) {
default:
case Gravity.LEFT:
// Nothing to do.
break;
case Gravity.RIGHT:
left += childWidth;
break;
case Gravity.CENTER_HORIZONTAL:
left += childWidth / 2;
break;
}
switch (vgrav) {
default:
case Gravity.TOP:
// Do nothing, we're already in position.
break;
case Gravity.BOTTOM:
top += childHeight;
break;
case Gravity.CENTER_VERTICAL:
top += childHeight / 2;
break;
}
// Obey margins and padding
left = Math.max(getPaddingLeft() + lp.leftMargin,
Math.min(left,
width - getPaddingRight() - childWidth - lp.rightMargin));
top = Math.max(getPaddingTop() + lp.topMargin,
Math.min(top,
height - getPaddingBottom() - childHeight - lp.bottomMargin));
child.layout(left, top, left + childWidth, top + childHeight);
}