本文整理匯總了Java中android.view.Gravity.NO_GRAVITY屬性的典型用法代碼示例。如果您正苦於以下問題:Java Gravity.NO_GRAVITY屬性的具體用法?Java Gravity.NO_GRAVITY怎麽用?Java Gravity.NO_GRAVITY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.view.Gravity
的用法示例。
在下文中一共展示了Gravity.NO_GRAVITY屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: showAsDropDown
/**
* fix showAsDropDown when android api ver is over N
* <p>
* https://code.google.com/p/android/issues/detail?id=221001
*
* @param anchor
* @param xoff
* @param yoff
* @param gravity
*/
@Override
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
if (isFixAndroidN && anchor != null) {
int[] anchorLocation = new int[2];
anchor.getLocationInWindow(anchorLocation);
Activity activity = (Activity) anchor.getContext();
xoff = anchorLocation[0] + xoff;
yoff = anchorLocation[1] + anchor.getHeight() + yoff;
setFocusable(false);
super.showAtLocation((activity).getWindow().getDecorView(), Gravity.NO_GRAVITY, xoff, yoff);
initSystemBar(getContentView());
setFocusable(true);
update();
} else {
if (isOverAndroidN) {
setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
}
setFocusable(false);
super.showAsDropDown(anchor, xoff, yoff, gravity);
initSystemBar(getContentView());
setFocusable(true);
update();
}
}
示例2: onAttachedToWindow
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (isInEditMode() && previewLayoutId != -1) {
for (int i = NUMBER_OF_SIMULTANEOUS_CARDS - 1; i >= 0; i--) {
View view = LayoutInflater.from(getContext()).inflate(previewLayoutId, this, false);
FrameLayout.LayoutParams params = (LayoutParams) view.getLayoutParams();
int offset = (int) (i * CARD_SPACING);
// All cards are placed in absolute coordinates, so disable gravity if we have any
params.gravity = Gravity.NO_GRAVITY;
// We can't user translations here, for some reason it's not rendered properly in preview
params.topMargin = offset;
view.setLayoutParams(params);
addViewInLayout(view, -1, params, true);
}
setZTranslations();
}
}
示例3: getAlignment
public Layout.Alignment getAlignment() {
boolean isRtl = getLayoutDirection() == YogaDirection.RTL;
switch (mAlignment) {
// Layout.Alignment.RIGHT and Layout.Alignment.LEFT are @hide :(
case Gravity.LEFT:
int index = isRtl ? ALIGNMENT_RIGHT : ALIGNMENT_LEFT;
return Layout.Alignment.values()[index];
case Gravity.RIGHT:
index = isRtl ? ALIGNMENT_LEFT : ALIGNMENT_RIGHT;
return Layout.Alignment.values()[index];
case Gravity.CENTER:
return Layout.Alignment.ALIGN_CENTER;
case Gravity.NO_GRAVITY:
default:
return Layout.Alignment.ALIGN_NORMAL;
}
}
示例4: showAsDropDownAtLocation
public void showAsDropDownAtLocation(View parent, int contentHeight, int x, int y) {
int screenWidth = getContentView().getResources().getDisplayMetrics().widthPixels;
int screenHeight = getContentView().getResources().getDisplayMetrics().heightPixels;
int width = getContentView().getMeasuredWidth();
int height = getContentView().getMeasuredHeight();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mLittleTriangle.getLayoutParams();
if (x + width > screenWidth) {
params.leftMargin = x + width - screenWidth;
} else if (x < 0) {
params.leftMargin = x;
} else {
params.leftMargin = 0;
}
if (y + height > screenHeight) {
getContentView().setRotation(180);
mRecyclerView.setRotation(180);
params.leftMargin = -params.leftMargin;
y -= contentHeight + height;
} else {
getContentView().setRotation(0);
mRecyclerView.setRotation(0);
}
mLittleTriangle.setLayoutParams(params);
super.showAtLocation(parent, Gravity.NO_GRAVITY, x, y);
}
示例5: setTextAlign
@ReactProp(name = ViewProps.TEXT_ALIGN)
public void setTextAlign(@Nullable String textAlign) {
if (textAlign == null || "auto".equals(textAlign)) {
mTextAlign = Gravity.NO_GRAVITY;
} else if ("left".equals(textAlign)) {
mTextAlign = Gravity.LEFT;
} else if ("right".equals(textAlign)) {
mTextAlign = Gravity.RIGHT;
} else if ("center".equals(textAlign)) {
mTextAlign = Gravity.CENTER_HORIZONTAL;
} else if ("justify".equals(textAlign)) {
// Fallback gracefully for cross-platform compat instead of error
mTextAlign = Gravity.LEFT;
} else {
throw new JSApplicationIllegalArgumentException("Invalid textAlign: " + textAlign);
}
markUpdated();
}
示例6: setTextAlign
@ReactProp(name = ViewProps.TEXT_ALIGN)
public void setTextAlign(@Nullable String textAlign) {
if (textAlign == null || "auto".equals(textAlign)) {
mAlignment = Gravity.NO_GRAVITY;
} else if ("left".equals(textAlign)) {
// left and right may yield potentially different results (relative to non-nodes) in cases
// when supportsRTL="true" in the manifest.
mAlignment = Gravity.LEFT;
} else if ("right".equals(textAlign)) {
mAlignment = Gravity.RIGHT;
} else if ("center".equals(textAlign)) {
mAlignment = Gravity.CENTER;
} else {
throw new JSApplicationIllegalArgumentException("Invalid textAlign: " + textAlign);
}
notifyChanged(false);
}
示例7: onTargetAlignmentChanged
@OnCheckedChanged({ R.id.target_align_start, R.id.target_align_center, R.id.target_align_end })
void onTargetAlignmentChanged(RadioButton button, boolean isChecked) {
if (isChecked) {
int alignment = Gravity.NO_GRAVITY;
switch (button.getId()) {
case R.id.target_align_start:
alignment = Gravity.START;
break;
case R.id.target_align_center:
alignment = Gravity.CENTER_HORIZONTAL;
break;
case R.id.target_align_end:
alignment = Gravity.END;
break;
}
onUpdateListener.updateTargetTextAlignment(alignment);
}
}
示例8: onRestoreInstanceState
@Override
protected void onRestoreInstanceState(Parcelable state) {
final SavedState ss = (SavedState) state;
super.onRestoreInstanceState(ss.getSuperState());
if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
final View toOpen = findDrawerWithGravity(ss.openDrawerGravity);
if (toOpen != null) {
openDrawer(toOpen);
}
}
setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
}
示例9: addView
@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);
}
示例10: generateLayoutParams
@Override
protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
if (p instanceof LayoutParams) {
LayoutParams result = new LayoutParams((LayoutParams) p);
if (result.gravity <= Gravity.NO_GRAVITY) {
result.gravity = Gravity.CENTER_VERTICAL;
}
return result;
}
return generateDefaultLayoutParams();
}
示例11: parseGravity
private static int parseGravity(String value) {
int gravity = Gravity.NO_GRAVITY;
String[] parts = value.toLowerCase().split("[|]");
for (String part : parts) {
switch (part) {
case "center":
gravity = gravity | Gravity.CENTER;
break;
case "left":
case "textStart":
gravity = gravity | Gravity.LEFT;
break;
case "right":
case "textEnd":
gravity = gravity | Gravity.RIGHT;
break;
case "top":
gravity = gravity | Gravity.TOP;
break;
case "bottom":
gravity = gravity | Gravity.BOTTOM;
break;
case "center_horizontal":
gravity = gravity | Gravity.CENTER_HORIZONTAL;
break;
case "center_vertical":
gravity = gravity | Gravity.CENTER_VERTICAL;
break;
}
}
return gravity;
}
示例12: showCategoriesPopupMenu
private void showCategoriesPopupMenu(final View view) {
final String allCategories = getString(R.string.all_categories);
final PopupMenu popupMenu =
new PopupMenu(this, view, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
final String title = String.valueOf(item.getTitle());
getFeedSubscriptionsFragment().changeSelectedCategory(title);
return true;
}
});
final Menu menu = popupMenu.getMenu();
menu.add(allCategories);
final Set<String> categories = SharedPrefUtils.getFeedMetaDataCategories(this);
for (final String category : categories) {
menu.add(category);
}
popupMenu.setGravity(Gravity.TOP);
popupMenu.show();
}
示例13: resolveGravity
private static int resolveGravity(int gravity) {
return gravity == Gravity.NO_GRAVITY ? GravityCompat.START | Gravity.TOP : gravity;
}
示例14: ArcTipViewController
private ArcTipViewController(Context application) {
mContext = application;
mWindowManager = (WindowManager) application.getSystemService(Context.WINDOW_SERVICE);
MAX_LENGTH = DEFAULT_MAX_LENGTH *SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f;
MIN_LENGTH = DEFAULT_MIN_LENGTH *SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f;
int resourceId = application.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
mStatusBarHeight = application.getResources().getDimensionPixelSize(resourceId);
}
mainHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
synchronized (ArcTipViewController.this) {
switch (msg.what) {
case MOVETOEDGE:
int desX = (int) msg.obj;
if (desX == 0) {
layoutParams.x = (int) (layoutParams.x - density * 10);
if (layoutParams.x < 0) {
layoutParams.x = 0;
}
} else {
layoutParams.x = (int) (layoutParams.x + density * 10);
if (layoutParams.x > desX) {
layoutParams.x = desX;
}
}
updateViewPosition(layoutParams.x, layoutParams.y);
if (layoutParams.x != desX) {
mainHandler.sendMessageDelayed(mainHandler.obtainMessage(MOVETOEDGE, desX), 10);
} else {
isMovingToEdge = false;
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
SPHelper.save(ConstantUtil.FLOAT_VIEW_PORT_X, layoutParams.x);
SPHelper.save(ConstantUtil.FLOAT_VIEW_PORT_Y, layoutParams.y);
} else {
SPHelper.save(ConstantUtil.FLOAT_VIEW_LAND_X, layoutParams.x);
SPHelper.save(ConstantUtil.FLOAT_VIEW_LAND_Y, layoutParams.y);
}
}
break;
case HIDETOEDGE:
if (layoutParams.x <= mScaledTouchSlop && ((layoutParams.gravity & (Gravity.TOP | Gravity.LEFT)) == (Gravity.TOP | Gravity.LEFT))) {
floatImageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.floatview_hide_left));
} else {
floatImageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.floatview_hide_right));
}
iconFloatView.setOnTouchListener(ArcTipViewController.this);
acrFloatView.setOnTouchListener(ArcTipViewController.this);
floatImageView.setContentDescription(mContext.getString(R.string.float_view_hide));
LinearLayout.LayoutParams layoutParams_ = (LinearLayout.LayoutParams) floatImageView.getLayoutParams();
layoutParams_.width = (int) ((int) ViewUtil.dp2px(DEFAULT_MIN_WIDTH_HIDE)*SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f);
layoutParams_.height = (int) ViewUtil.dp2px(MIN_LENGTH);
layoutParams_.gravity = Gravity.NO_GRAVITY;
floatImageView.setLayoutParams(layoutParams_);
floatImageView.setPadding(0,0,0,0);
//TODO 不貼邊的問題
// layoutParams.width = (int) ViewUtil.dp2px(DEFAULT_MIN_WIDTH_HIDE);
reuseSavedWindowMangerPosition((int) (ViewUtil.dp2px(DEFAULT_MIN_WIDTH_HIDE)*SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f), ViewUtil.dp2px(MIN_LENGTH));
updateViewPosition(layoutParams.x, layoutParams.y);
break;
}
}
}
};
mActionListener = new ArrayList<>();
mScaledTouchSlop = (int) (ViewUtil.dp2px(DEFAULT_MIN_WIDTH_HIDE)*SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f);
initView();
applySizeChange();
isRemoved = true;
}
示例15: isContentView
boolean isContentView(View child) {
return ((LayoutParams) child.getLayoutParams()).gravity == Gravity.NO_GRAVITY;
}