List of usage examples for android.view Gravity CENTER_HORIZONTAL
int CENTER_HORIZONTAL
To view the source code for android.view Gravity CENTER_HORIZONTAL.
Click Source Link
From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java
private void displayAlertWithMessage(String errorcode) { String errorMessage = getResources().getString(R.string.alert_message_write_error) + "\n" + getResources().getString(R.string.alert_message_write_error_code) + errorcode + "\n" + getResources().getString(R.string.alert_message_try_again); AlertDialog alert;//from ww w.j av a 2 s. c o m AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); TextView myMsg = new TextView(getActivity()); myMsg.setText(errorMessage); myMsg.setGravity(Gravity.CENTER_HORIZONTAL); builder.setView(myMsg); builder.setTitle(getActivity().getResources().getString(R.string.app_name)).setCancelable(false) .setPositiveButton(getActivity().getResources().getString(R.string.alert_message_exit_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); alert = builder.create(); alert.setCanceledOnTouchOutside(false); alert.show(); }
From source file:com.sender.team.sender.gcm.MyGcmListenerService.java
private void sendToast(final ChattingReceiveData data, final ChattingReceiveMessage c) { handler.post(new Runnable() { @Override//from w w w . j ava 2 s . c o m public void run() { View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.toast_notify, null); ImageView imageProfile = (ImageView) view.findViewById(R.id.imageProfile); TextView textName = (TextView) view.findViewById(R.id.textName); TextView textMessage = (TextView) view.findViewById(R.id.textMessage); Glide.with(getApplicationContext()).load(data.getSender().getFileUrl()).into(imageProfile); if (!TextUtils.isEmpty(data.getSender().getName())) { textName.setText(data.getSender().getName()); } if (!TextUtils.isEmpty(c.getMessage())) { textMessage.setText(c.getMessage()); } else { textMessage.setText(""); } Toast toast = new Toast(getApplicationContext()); float dp = 65; int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, pixel); toast.setDuration(Toast.LENGTH_LONG); toast.setView(view); toast.show(); } }); }
From source file:org.getlantern.firetweet.activity.support.QuickSearchBarActivity.java
private void updateWindowAttributes() { final Window window = getWindow(); final WindowManager.LayoutParams attributes = window.getAttributes(); attributes.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; attributes.y = mSystemWindowsInsets.top; window.setAttributes(attributes);/*from w w w . j a va 2 s . c om*/ }
From source file:com.acbelter.directionalcarousel.CarouselViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int width = MeasureSpec.getSize(widthMeasureSpec); final int height = MeasureSpec.getSize(heightMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (DEBUG) {//ww w. jav a2s.c o m Log.d(TAG, "w=" + width + " h=" + height); Log.d(TAG, "wMode=" + getModeDescription(widthMode) + " hMode=" + getModeDescription(heightMode)); } // FIXME Supported only match_parent and wrap_content attributes if (mConfig.orientation == CarouselConfig.VERTICAL) { int pageContentWidth = getPageContentWidth(); int newWidth = width; if (widthMode == MeasureSpec.AT_MOST || pageContentWidth + 2 * mWrapPadding > width) { newWidth = pageContentWidth + 2 * mWrapPadding; widthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth, widthMode); } ViewGroup.LayoutParams lp = getLayoutParams(); // FIXME Supported only FrameLayout as parent if (lp instanceof FrameLayout.LayoutParams) { if (!parentHasExactDimensions()) { throw new UnsupportedOperationException("Parent layout should have exact " + "dimensions."); } FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lp; if (!mSizeChanged) { gravityOffset = 0.0f; int hGrav = params.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; if (hGrav == Gravity.CENTER_HORIZONTAL || hGrav == Gravity.CENTER) { gravityOffset = (width - newWidth) * 0.5f; } if (hGrav == Gravity.RIGHT) { gravityOffset = width - newWidth; } } setRotation(90); setTranslationX((newWidth - height) * 0.5f + gravityOffset); setTranslationY(-(newWidth - height) * 0.5f); params.gravity = Gravity.NO_GRAVITY; setLayoutParams(params); } else { throw new UnsupportedOperationException("Parent layout should be instance of " + "FrameLayout."); } mSizeChanged = true; super.onMeasure(heightMeasureSpec, widthMeasureSpec); } else { int pageContentHeight = getPageContentHeight(); if (heightMode == MeasureSpec.AT_MOST || pageContentHeight + 2 * mWrapPadding > height) { int newHeight = pageContentHeight + 2 * mWrapPadding; heightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight, heightMode); } // FIXME Supported only FrameLayout as parent if (!(getLayoutParams() instanceof FrameLayout.LayoutParams)) { throw new UnsupportedOperationException("Parent layout should be instance of " + "FrameLayout."); } else { if (!parentHasExactDimensions()) { throw new UnsupportedOperationException("Parent layout should have exact " + "dimensions."); } } mSizeChanged = true; super.onMeasure(widthMeasureSpec, heightMeasureSpec); } mViewPagerWidth = getMeasuredWidth(); mViewPagerHeight = getMeasuredHeight(); if (calculatePageLimitAndMargin()) { setOffscreenPageLimit(mConfig.pageLimit); setPageMargin(mConfig.pageMargin); } if (DEBUG) { Log.d(TAG, mConfig.toString()); } }
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. j a v a 2 s . c o m*/ 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:com.easemob.easeui.widget.viewpagerindicator.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);/*from ww w. j ava 2 s . c o m*/ tab.setSingleLine(); tab.setTextColor(tabTextColor); tab.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); addTab(position, tab); }
From source file:despotoski.nikola.github.com.bottomnavigationlayout.BottomTabLayout.java
private void setupContainer() { mContainer = new LinearLayoutCompat(getContext()); mContainer.setFocusable(false);/*from w w w . j a v a 2s . com*/ LayoutParams layoutParams; if (isTablet) { layoutParams = new LayoutParams(mMaxContainerHeight, LayoutParams.MATCH_PARENT); layoutParams.gravity = Gravity.CENTER_VERTICAL; disableBehavior(); mContainer.setOrientation(LinearLayoutCompat.VERTICAL); mContainer.setGravity(Gravity.TOP | Gravity.CENTER_VERTICAL); addView(mContainer, layoutParams); } else { mContainer.setOrientation(LinearLayoutCompat.HORIZONTAL); mContainer.setPadding(0, 0, (int) getResources().getDimension(R.dimen.bottom_navigation_item_padding_bottom), 0); layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.bottom_navigation_height)); layoutParams.gravity = Gravity.TOP; layoutParams.bottomMargin = !isInEditMode() && Util.isNavigationBarTranslucent(getContext()) && !isLandscape() ? Util.getNavigationBarHeight(getContext()) : 0; mContainer.setOrientation(LinearLayoutCompat.HORIZONTAL); mContainer.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL); addView(mContainer, layoutParams); } }
From source file:com.zxly.o2o.view.MPagerSlidingTab.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setPadding(DesityUtil.dp2px(getContext(), 6), 0, DesityUtil.dp2px(getContext(), 6), 0); tab.setText(title);//from ww w . ja va2 s . c o m tab.setSingleLine(); tab.setTextColor(tabTextColor); tab.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); addTab(position, tab); }
From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java
/** * Creates and positions all views for this Spinner. * * @param delta Change in the selected position. +1 moves selection is moving to the right, * so views are scrolling to the left. -1 means selection is moving to the left. *///from ww w .j ava2 s . com @Override void layout(int delta, boolean animate) { int childrenLeft = mSpinnerPadding.left; int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right; if (mDataChanged) { handleDataChanged(); } // Handle the empty set by removing all views if (mItemCount == 0) { resetList(); return; } if (mNextSelectedPosition >= 0) { setSelectedPositionInt(mNextSelectedPosition); } recycleAllViews(); // Clear out old views removeAllViewsInLayout(); // Make selected view and position it mFirstPosition = mSelectedPosition; View sel = makeAndAddView(mSelectedPosition); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2); break; case Gravity.RIGHT: selectedOffset = childrenLeft + childrenWidth - width; break; } sel.offsetLeftAndRight(selectedOffset); // Flush any cached views that did not get reused above mRecycler.clear(); invalidate(); checkSelectionChanged(); mDataChanged = false; mNeedSync = false; setNextSelectedPositionInt(mSelectedPosition); }
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();/* w ww .jav a 2 s. co 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 }; }