List of usage examples for android.view Gravity BOTTOM
int BOTTOM
To view the source code for android.view Gravity BOTTOM.
Click Source Link
From source file:com.cooltechworks.views.ScratchTextView.java
private int[] getTextBounds(float scale) { int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); int paddingRight = getPaddingRight(); int paddingBottom = getPaddingBottom(); int vwidth = getWidth(); int vheight = getHeight(); int centerX = vwidth / 2; int centerY = vheight / 2; TextPaint paint = getPaint();//ww w .ja v a2s . c o m String text = getText().toString(); int[] dimens = getTextDimens(text, paint); int width = dimens[0]; int height = dimens[1]; int lines = getLineCount(); height = height * lines; width = width / lines; int left = 0; int top = 0; if (height > vheight) { height = vheight - (paddingBottom + paddingTop); } else { height = (int) (height * scale); } if (width > vwidth) { width = vwidth - (paddingLeft + paddingRight); } else { width = (int) (width * scale); } int gravity = getGravity(); //todo Gravity.START if ((gravity & Gravity.LEFT) == Gravity.LEFT) { left = paddingLeft; } //todo Gravity.END else if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) { left = (vwidth - paddingRight) - width; } else if ((gravity & Gravity.CENTER_HORIZONTAL) == Gravity.CENTER_HORIZONTAL) { left = centerX - width / 2; } if ((gravity & Gravity.TOP) == Gravity.TOP) { top = paddingTop; } else if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) { top = (vheight - paddingBottom) - height; } else if ((gravity & Gravity.CENTER_VERTICAL) == Gravity.CENTER_VERTICAL) { top = centerY - height / 2; } return new int[] { left, top, left + width, top + height }; }
From source file:com.googlecode.android_scripting.activity.Main.java
protected void initializeViews() { LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); layout.setGravity(Gravity.CENTER_HORIZONTAL); TextView textview = new TextView(this); textview.setText(" PhpForAndroid " + version); ImageView imageView = new ImageView(this); imageView.setImageDrawable(getResources().getDrawable(R.drawable.pfa)); layout.addView(imageView);// w w w. java2s. c om mButton = new Button(this); mAboutButton = new Button(this); MarginLayoutParams marginParams = new MarginLayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); final float scale = getResources().getDisplayMetrics().density; int marginPixels = (int) (MARGIN_DIP * scale + 0.5f); marginParams.setMargins(marginPixels, marginPixels, marginPixels, marginPixels); mButton.setLayoutParams(marginParams); mAboutButton.setLayoutParams(marginParams); layout.addView(textview); layout.addView(mButton); layout.addView(mAboutButton); mProgressLayout = new LinearLayout(this); mProgressLayout.setOrientation(LinearLayout.HORIZONTAL); mProgressLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mProgressLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL); LinearLayout bottom = new LinearLayout(this); bottom.setOrientation(LinearLayout.HORIZONTAL); bottom.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); bottom.setGravity(Gravity.CENTER_VERTICAL); mProgressLayout.addView(bottom); TextView message = new TextView(this); message.setText(" In Progress..."); message.setTextSize(20); message.setTypeface(Typeface.DEFAULT_BOLD); message.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); ProgressBar bar = new ProgressBar(this); bar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); bottom.addView(bar); bottom.addView(message); mProgressLayout.setVisibility(View.INVISIBLE); layout.addView(mProgressLayout); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setProgressBarIndeterminateVisibility(false); setContentView(layout); }
From source file:bmcx.aiton.com.passenger.view.activity.UploadUserDataActivity.java
/** * POP?/*from w ww . j a va 2 s. c o m*/ */ private void showPopupwindowForChooseImageStage() { View inflate = getLayoutInflater().inflate(R.layout.layout_pop_choose_img_stage, null); inflate.findViewById(R.id.click_local).setOnClickListener(this); inflate.findViewById(R.id.click_camera).setOnClickListener(this); inflate.findViewById(R.id.cancle).setOnClickListener(this); //??truePopupWindow,match?? mPopupWindow = new PopupWindow(inflate, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); // mPopupWindow.setOutsideTouchable(false); //? WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.alpha = 0.7f; getWindow().setAttributes(lp); mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.alpha = 1f; getWindow().setAttributes(lp); } }); // ?PopupWindowBackdismiss BitmapDrawable bitmapDrawable = new BitmapDrawable(); mPopupWindow.setBackgroundDrawable(bitmapDrawable); mPopupWindow.showAtLocation(inflate, Gravity.BOTTOM, 0, 0); }
From source file:com.tencent.tws.assistant.widget.CheckBox.java
private void setRippleBackground(boolean isSupportTintDrawable, Drawable orgDrawable, int rippleColor) { if (orgDrawable != null && isSupportTintDrawable) { ColorStateList csl = createNormalStateList(rippleColor); final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; final int drawableHeight = orgDrawable.getIntrinsicHeight(); final int drawableWidth = orgDrawable.getIntrinsicWidth(); final float scale = 0.3f; final float drawableScaleHeight = drawableHeight * scale; final float drawableScaleWidth = drawableWidth * scale; final int top; switch (verticalGravity) { case Gravity.BOTTOM: top = (int) (getHeight() - drawableHeight - drawableScaleHeight); break; case Gravity.CENTER_VERTICAL: top = (int) (((getHeight() - drawableHeight) / 2) - drawableScaleHeight); break; default:// ww w .j a va 2 s .c o m top = (int) (-drawableScaleHeight); } final int bottom = (int) (top + drawableHeight + drawableScaleHeight * 2); final int left = (int) (isLayoutRtl() ? getWidth() - drawableWidth - drawableScaleWidth : -drawableScaleWidth); final int right = (int) (isLayoutRtl() ? getWidth() + drawableScaleWidth : drawableWidth + drawableScaleWidth); TwsRippleDrawable rippleDrawable = new TwsRippleDrawable(csl, null, null, TwsRippleDrawable.RIPPLE_STYLE_RING); rippleDrawable.twsSetHotspotBounds(left, top, right, bottom); setBackgroundDrawable(rippleDrawable); } }
From source file:android.support.v7.app.MediaRouteButton.java
@Override public boolean performLongClick() { if (super.performLongClick()) { return true; }/*www. j ava 2s .c o m*/ if (!mCheatSheetEnabled) { return false; } final CharSequence contentDesc = getContentDescription(); if (TextUtils.isEmpty(contentDesc)) { // Don't show the cheat sheet if we have no description return false; } final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; Toast cheatSheet = Toast.makeText(context, contentDesc, Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, screenWidth - screenPos[0] - width / 2, height); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); return true; }
From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java
/** * Set a simple drawable used for the left or right shadow. * The drawable provided must have a nonzero intrinsic width. * /* w ww . j a va 2s . c o m*/ * @param shadowDrawable * Shadow drawable to use at the edge of a drawer * @param gravity * Which drawer the shadow should apply to */ public void setDrawerShadow(Drawable shadowDrawable, int gravity) { /* * TODO Someone someday might want to set more complex drawables here. * They're probably nuts, but we might want to consider registering * callbacks, * setting states, etc. properly. */ final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this)); if ((absGravity & Gravity.TOP) == Gravity.TOP) { mShadowTop = shadowDrawable; invalidate(); } if ((absGravity & Gravity.BOTTOM) == Gravity.BOTTOM) { mShadowBottom = shadowDrawable; invalidate(); } }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
/** * Enable or disable interaction with the given drawer. * /*from w w w . j av a2s .c o m*/ * <p> * This allows the application to restrict the user's ability to open or * close the given drawer. DrawerLayout will still respond to calls to * {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends if a * drawer is locked. * </p> * * <p> * Locking a drawer open or closed will implicitly open or close that drawer * as appropriate. * </p> * * @param lockMode * The new lock mode for the given drawer. One of * {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} * or {@link #LOCK_MODE_LOCKED_OPEN}. * @param edgeGravity * Gravity.LEFT, RIGHT, START or END. Expresses which drawer to * change the mode for. * * @see #LOCK_MODE_UNLOCKED * @see #LOCK_MODE_LOCKED_CLOSED * @see #LOCK_MODE_LOCKED_OPEN */ public void setDrawerLockMode(int lockMode, int edgeGravity) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.BOTTOM) { mLockModeBottom = lockMode; } if (lockMode != LOCK_MODE_UNLOCKED) { if (absGravity == Gravity.BOTTOM) { final ViewDragHelper helper = mBottomDragger; helper.cancel(); } } switch (lockMode) { case LOCK_MODE_LOCKED_OPEN: final View toOpen = findDrawerWithGravity(absGravity); if (toOpen != null) { openDrawer(toOpen); } break; case LOCK_MODE_LOCKED_CLOSED: final View toClose = findDrawerWithGravity(absGravity); if (toClose != null) { closeDrawer(toClose); } break; } }
From source file:com.bf.zxd.zhuangxudai.my.fragment.FinancialApplyFragment.java
private void ChangeIcon() { //PopupWindow----START-----??PopupWindowPopupWindow??? backgroundAlpha(0.3f);/*ww w . jav a 2 s. c om*/ View view = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.popu_window, null); final PopupWindow popupWindow = new PopupWindow(view, ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, true); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); //?? DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); popupWindow.setWidth(dm.widthPixels); popupWindow.setAnimationStyle(R.style.popuwindow); //? popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0); popupWindow.setOnDismissListener(new poponDismissListener_FinancialApplyFragment()); //PopupWindow-----END //PopupWindow Button button = (Button) view.findViewById(R.id.take_photo);//?? Button button1 = (Button) view.findViewById(R.id.all_photo);//? Button button2 = (Button) view.findViewById(R.id.out);//? button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { backgroundAlpha(1f); popupWindow.dismiss(); } }); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { backgroundAlpha(1f); popupWindow.dismiss(); //,? allPhoto(); } }); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { backgroundAlpha(1f); popupWindow.dismiss(); //,Intent???? Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //,?? File file = FileUitlity.getInstance(getActivity().getApplicationContext()).makeDir("head_image"); //?? path = file.getParent() + File.separatorChar + System.currentTimeMillis() + ".jpg"; //?IntentIntent? intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path))); //? intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); //?Intent??RoundImageView startActivityForResult(intent, REQUEST_CODE); } }); }
From source file:android.support.designox.widget.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom; break;// w w w. jav a2s. c o m case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.htc.dotdesign.ToolBoxService.java
private void setToolPanelVisibility(boolean bShow) { if (mCurrExtend != null) { mWindowManager.removeView(mCurrExtend); mCurrExtend = null;//w w w.j av a 2 s. co m } if (bShow) { mIsToolBarExtend = true; if (mCurrFun == FunType.Fun_Palette) { Resources res = getResources(); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); params.gravity = Gravity.START; if (mDragButtonParams.y < mScreenHeight / 2) { params.gravity = Gravity.TOP | params.gravity; params.y = mDragButtonParams.y + mDragButtonHeight; View top_arrow = mPalette.findViewById(R.id.top_arrow); top_arrow.setVisibility(View.VISIBLE); View bottom_arrow = mPalette.findViewById(R.id.bottom_arrow); bottom_arrow.setVisibility(View.GONE); } else { params.gravity = Gravity.BOTTOM | params.gravity; params.y = mScreenHeight - mDragButtonParams.y; View top_arrow = mPalette.findViewById(R.id.top_arrow); top_arrow.setVisibility(View.GONE); View bottom_arrow = mPalette.findViewById(R.id.bottom_arrow); bottom_arrow.setVisibility(View.VISIBLE); } int[] locations = new int[2]; mBtnPalette.getLocationOnScreen(locations); int x = locations[0]; params.x = (x + mBtnPalette.getWidth() / 2) - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02)); mPalette.setVisibility(View.VISIBLE); mWindowManager.addView(mPalette, params); mCurrExtend = mPalette; initBrushSize(); } else if (mCurrFun == FunType.Fun_Eraser) { Resources res = getResources(); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); params.gravity = Gravity.START; if (mDragButtonParams.y < mScreenHeight / 2) { params.gravity = Gravity.TOP | params.gravity; params.y = mDragButtonParams.y + mDragButtonHeight; View top_arrow = mEraser.findViewById(R.id.top_arrow); top_arrow.setVisibility(View.VISIBLE); View bottom_arrow = mEraser.findViewById(R.id.bottom_arrow); bottom_arrow.setVisibility(View.GONE); } else { params.gravity = Gravity.BOTTOM | params.gravity; params.y = mScreenHeight - mDragButtonParams.y; View top_arrow = mEraser.findViewById(R.id.top_arrow); top_arrow.setVisibility(View.GONE); View bottom_arrow = mEraser.findViewById(R.id.bottom_arrow); bottom_arrow.setVisibility(View.VISIBLE); } int[] locations = new int[2]; mBtnEraser.getLocationOnScreen(locations); int x = locations[0]; params.x = (x + mBtnEraser.getWidth() / 2) - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02)); mEraser.setVisibility(View.VISIBLE); mWindowManager.addView(mEraser, params); mCurrExtend = mEraser; initBrushSize(); } else if (mCurrFun == FunType.Fun_VirtualDot) { } else if (mCurrFun == FunType.Fun_Menu) { Resources res = getResources(); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); params.gravity = Gravity.END; if (mDragButtonParams.y < mScreenHeight / 2) { params.gravity = Gravity.TOP | params.gravity; params.y = mDragButtonParams.y + mDragButtonHeight; // Set top_arrow to visible and align to parent right. View top_arrow = mMenu.findViewById(R.id.top_arrow); top_arrow.setVisibility(View.VISIBLE); LinearLayout.LayoutParams arrowParams = (LinearLayout.LayoutParams) top_arrow.getLayoutParams(); arrowParams.setMarginEnd(res.getDimensionPixelSize(R.dimen.h02)); arrowParams.gravity = Gravity.END; top_arrow.setLayoutParams(arrowParams); // Set bottom_arrow to gone View bottom_arrow = mMenu.findViewById(R.id.bottom_arrow); bottom_arrow.setVisibility(View.GONE); } else { params.gravity = Gravity.BOTTOM | params.gravity; params.y = mScreenHeight - mDragButtonParams.y; // Set top_arrow to gone View top_arrow = mMenu.findViewById(R.id.top_arrow); top_arrow.setVisibility(View.GONE); // Set bottom_arrow to visible and align to parent right. View bottom_arrow = mMenu.findViewById(R.id.bottom_arrow); LinearLayout.LayoutParams arrowParams = (LinearLayout.LayoutParams) bottom_arrow .getLayoutParams(); arrowParams.setMarginEnd(res.getDimensionPixelSize(R.dimen.h02)); arrowParams.gravity = Gravity.END; bottom_arrow.setLayoutParams(arrowParams); bottom_arrow.setVisibility(View.VISIBLE); } int[] locations = new int[2]; mBtnMenu.getLocationOnScreen(locations); int x = locations[0]; //params.x = (x + mBtnMenu.getWidth()/2) - (mArrowWidth/2 + res.getDimensionPixelSize(R.dimen.h02)); params.x = mScreenWidth - (x + mBtnMenu.getWidth() / 2) - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02)); mMenu.setVisibility(View.VISIBLE); mWindowManager.addView(mMenu, params); mCurrExtend = mMenu; } } else { mIsToolBarExtend = false; } updateToolBarFunIconColor(); }