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.android.contacts.list.ContactsUnavailableFragment.java
/** * Update views in the fragment when provider status is busy. * * @param resId resource ID of the string to show in mMessageView. *//* w ww .ja v a 2 s .c o m*/ private void updateViewsForBusyStatus(int resId) { mMessageView.setText(resId); mMessageView.setGravity(Gravity.CENTER_HORIZONTAL); mMessageView.setVisibility(View.VISIBLE); updateButtonVisibilty(View.GONE); mProgress.setVisibility(View.VISIBLE); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mMessageView.getLayoutParams(); final int marginTop = (int) getResources().getDimension(R.dimen.update_contact_list_top_margin); lp.setMargins(0, marginTop, 0, 0); mImageView.setVisibility(View.GONE); } else { mImageView.setVisibility(View.INVISIBLE); } }
From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java
/** * SINGLE TITLE ROW// ww w. j a v a 2s . c o m * @param att * @param linear * @return */ public LinearLayout getSingleTitleRow(Map<String, String> att, LinearLayout linear) { LinearLayout container_layout = new LinearLayout(context); container_layout.setMinimumHeight(30); container_layout .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue)); container_layout.setVerticalGravity(Gravity.CENTER); LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.5f); TextView tx = new TextView(context); tx.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(tx, value_params); LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.5f); TextView t1 = new TextView(context); t1.setText(att.get("value")); t1.setTextSize(11); t1.setGravity(Gravity.CENTER_HORIZONTAL); t1.setPadding(2, 0, 0, 2); t1.setTextColor(Color.rgb(255, 255, 255)); container_layout.addView(t1, ltext1); linear.addView(container_layout); return linear; }
From source file:android.support.design.internal.BottomNavigationItemView.java
@Override public void setChecked(boolean checked) { ViewCompat.setPivotX(mLargeLabel, mLargeLabel.getWidth() / 2); ViewCompat.setPivotY(mLargeLabel, mLargeLabel.getBaseline()); ViewCompat.setPivotX(mSmallLabel, mSmallLabel.getWidth() / 2); ViewCompat.setPivotY(mSmallLabel, mSmallLabel.getBaseline()); if (mShiftingMode) { if (checked) { LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams(); iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; iconParams.topMargin = mDefaultMargin; mIcon.setLayoutParams(iconParams); mLargeLabel.setVisibility(VISIBLE); ViewCompat.setScaleX(mLargeLabel, 1f); ViewCompat.setScaleY(mLargeLabel, 1f); } else {/*from w ww .jav a 2 s . c om*/ LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams(); iconParams.gravity = Gravity.CENTER; iconParams.topMargin = mDefaultMargin; mIcon.setLayoutParams(iconParams); mLargeLabel.setVisibility(INVISIBLE); ViewCompat.setScaleX(mLargeLabel, 0.5f); ViewCompat.setScaleY(mLargeLabel, 0.5f); } mSmallLabel.setVisibility(INVISIBLE); } else { if (checked) { LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams(); iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; iconParams.topMargin = mDefaultMargin + mShiftAmount; mIcon.setLayoutParams(iconParams); mLargeLabel.setVisibility(VISIBLE); mSmallLabel.setVisibility(INVISIBLE); ViewCompat.setScaleX(mLargeLabel, 1f); ViewCompat.setScaleY(mLargeLabel, 1f); ViewCompat.setScaleX(mSmallLabel, mScaleUpFactor); ViewCompat.setScaleY(mSmallLabel, mScaleUpFactor); } else { LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams(); iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; iconParams.topMargin = mDefaultMargin; mIcon.setLayoutParams(iconParams); mLargeLabel.setVisibility(INVISIBLE); mSmallLabel.setVisibility(VISIBLE); ViewCompat.setScaleX(mLargeLabel, mScaleDownFactor); ViewCompat.setScaleY(mLargeLabel, mScaleDownFactor); ViewCompat.setScaleX(mSmallLabel, 1f); ViewCompat.setScaleY(mSmallLabel, 1f); } } refreshDrawableState(); }
From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java
public void createButtonWithText(Activity activity, ViewGroup l, String text, String button, View.OnClickListener onclick) { RelativeLayout r = new RelativeLayout(activity); r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); TextView tv = new TextView(activity); RelativeLayout.LayoutParams tvparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); tvparams.addRule(RelativeLayout.ABOVE, R.id.reload_button); tvparams.addRule(RelativeLayout.CENTER_HORIZONTAL); tv.setLayoutParams(tvparams);//from w w w. j a va2s.co m tv.setText(text); tv.setTextSize(23); tv.setPadding(0, 0, 0, toPixels(15)); tv.setGravity(Gravity.CENTER_HORIZONTAL); r.addView(tv); Button b = new Button(activity); RelativeLayout.LayoutParams bparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); bparams.addRule(RelativeLayout.CENTER_VERTICAL); bparams.addRule(RelativeLayout.CENTER_HORIZONTAL); b.setLayoutParams(bparams); b.setId(R.id.reload_button); b.setText(button); b.setTextSize(23); b.setAllCaps(false); b.setTypeface(null, Typeface.NORMAL); b.setOnClickListener(onclick); r.addView(b); l.addView(r); }
From source file:saphion.pageindicators.FixedTabsView.java
/** * Initialize and add all tabs to the layout *//*from w ww . ja v a 2 s.co m*/ private void initTabs() { removeAllViews(); mTabs.clear(); if (mAdapter == null) return; for (int i = 0; i < mPager.getAdapter().getCount(); i++) { final int index = i; View tab = mAdapter.getView(i); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f); tab.setLayoutParams(params); this.addView(tab); mTabs.add(tab); if (i != mPager.getAdapter().getCount() - 1) { this.addView(getSeparator()); } tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(index); } }); tab.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { //Toast t = new Toast(getContext()); Toast t = Toast.makeText(mContext, "", Toast.LENGTH_SHORT); //t.setGravity(Gravity.TOP, v.getRight()/2 - v.getLeft()/2, v.getBottom()); switch (index) { case 0: t.setText("Power Profiles"); t.setGravity(Gravity.TOP | Gravity.LEFT, v.getLeft(), v.getBottom()); break; case 1: t.setText("Battery Info"); t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, v.getBottom()); break; case 2: t.setText("Graph and Stats"); t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, v.getBottom()); break; case 3: t.setText("Battery Alarms"); t.setGravity(Gravity.TOP, v.getLeft(), v.getBottom()); break; } t.setDuration(Toast.LENGTH_SHORT); t.show(); return true; } }); } selectTab(mPager.getCurrentItem()); }
From source file:com.tmall.wireless.tangram.view.BannerView.java
public void setIndicatorGravity(int gravity) { switch (gravity) { case GRAVITY_LEFT: if (mIndicator != null) { mIndicator.setGravity(Gravity.LEFT); }/*from w ww . j a v a2s . co m*/ break; case GRAVITY_CENTER: if (mIndicator != null) { mIndicator.setGravity(Gravity.CENTER_HORIZONTAL); } break; case GRAVITY_RIGHT: if (mIndicator != null) { mIndicator.setGravity(Gravity.RIGHT); } break; } }
From source file:com.example.tt.pullrefresh.widget.CurveLayout.java
@Override public void addView(View child, int index, ViewGroup.LayoutParams params) { if (sheet != null) { throw new UnsupportedOperationException("CurveLayout must only have 1 child view"); }//from w w w . j a va2 s. com sheet = child; sheetOffsetHelper = new ViewOffsetHelper(sheet); sheet.addOnLayoutChangeListener(sheetLayout); // force the sheet contents to be gravity bottom. This ain't a top sheet. ((LayoutParams) params).gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; super.addView(child, index, params); }
From source file:cn.jay.widget.BottomNavigationItemView.java
@Override public void setChecked(boolean checked) { mItemData.setChecked(checked);/*from w w w . j a va 2s . c om*/ if (mUseStandardDesign) { ViewCompat.setPivotX(mLargeLabel, mLargeLabel.getWidth() / 2); ViewCompat.setPivotY(mLargeLabel, mLargeLabel.getBaseline()); ViewCompat.setPivotX(mSmallLabel, mSmallLabel.getWidth() / 2); ViewCompat.setPivotY(mSmallLabel, mSmallLabel.getBaseline()); if (mShiftingMode) { if (checked) { LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams(); iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; iconParams.topMargin = mDefaultMargin; mIcon.setLayoutParams(iconParams); mLargeLabel.setVisibility(VISIBLE); ViewCompat.setScaleX(mLargeLabel, 1f); ViewCompat.setScaleY(mLargeLabel, 1f); } else { LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams(); iconParams.gravity = Gravity.CENTER; iconParams.topMargin = mDefaultMargin; mIcon.setLayoutParams(iconParams); mLargeLabel.setVisibility(INVISIBLE); ViewCompat.setScaleX(mLargeLabel, 0.5f); ViewCompat.setScaleY(mLargeLabel, 0.5f); } mSmallLabel.setVisibility(INVISIBLE); } else { if (checked) { LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams(); iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; iconParams.topMargin = mDefaultMargin + mShiftAmount; mIcon.setLayoutParams(iconParams); mLargeLabel.setVisibility(VISIBLE); mSmallLabel.setVisibility(INVISIBLE); ViewCompat.setScaleX(mLargeLabel, 1f); ViewCompat.setScaleY(mLargeLabel, 1f); ViewCompat.setScaleX(mSmallLabel, mScaleUpFactor); ViewCompat.setScaleY(mSmallLabel, mScaleUpFactor); } else { LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams(); iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; iconParams.topMargin = mDefaultMargin; mIcon.setLayoutParams(iconParams); mLargeLabel.setVisibility(INVISIBLE); mSmallLabel.setVisibility(VISIBLE); ViewCompat.setScaleX(mLargeLabel, mScaleDownFactor); ViewCompat.setScaleY(mLargeLabel, mScaleDownFactor); ViewCompat.setScaleX(mSmallLabel, 1f); ViewCompat.setScaleY(mSmallLabel, 1f); } } } refreshDrawableState(); }
From source file:com.twolinessoftware.smarterlist.activity.BaseActivity.java
public void showErrorCrouton(String message) { Style style = new Style.Builder().setHeightDimensionResId(R.dimen.crouton_height) .setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM) .setBackgroundColorValue(getResources().getColor(R.color.pal_red)) .setTextAppearance(R.style.SmarterList_TextStyle_Body_Bold).build(); Crouton.makeText(this, message, style, R.id.container).show(); }
From source file:com.mifos.mifosxdroid.online.datatablelistfragment.DataTableListFragment.java
public void createForm(DataTable table) { TextView tableName = new TextView(getActivity().getApplicationContext()); tableName.setText(table.getRegisteredTableName()); tableName.setGravity(Gravity.CENTER_HORIZONTAL); tableName.setTypeface(null, Typeface.BOLD); tableName.setTextColor(getActivity().getResources().getColor(R.color.black)); tableName.setTextSize(TypedValue.COMPLEX_UNIT_SP, getActivity().getResources().getDimension(R.dimen.datatable_name_heading)); linearLayout.addView(tableName);/* w w w . j a v a 2 s. c o m*/ List<FormWidget> formWidgets = new ArrayList<FormWidget>(); for (ColumnHeader columnHeader : table.getColumnHeaderData()) { if (!columnHeader.getColumnPrimaryKey()) { if (columnHeader.getColumnDisplayType().equals(FormWidget.SCHEMA_KEY_STRING) || columnHeader.getColumnDisplayType().equals(FormWidget.SCHEMA_KEY_TEXT)) { FormEditText formEditText = new FormEditText(getActivity(), columnHeader.getColumnName()); formWidgets.add(formEditText); linearLayout.addView(formEditText.getView()); } else if (columnHeader.getColumnDisplayType().equals(FormWidget.SCHEMA_KEY_INT)) { FormNumericEditText formNumericEditText = new FormNumericEditText(getActivity(), columnHeader.getColumnName()); formNumericEditText.setReturnType(FormWidget.SCHEMA_KEY_INT); formWidgets.add(formNumericEditText); linearLayout.addView(formNumericEditText.getView()); } else if (columnHeader.getColumnDisplayType().equals(FormWidget.SCHEMA_KEY_DECIMAL)) { FormNumericEditText formNumericEditText = new FormNumericEditText(getActivity(), columnHeader.getColumnName()); formNumericEditText.setReturnType(FormWidget.SCHEMA_KEY_DECIMAL); formWidgets.add(formNumericEditText); linearLayout.addView(formNumericEditText.getView()); } else if (columnHeader.getColumnDisplayType().equals(FormWidget.SCHEMA_KEY_CODELOOKUP) || columnHeader.getColumnDisplayType().equals(FormWidget.SCHEMA_KEY_CODEVALUE)) { if (columnHeader.getColumnValues().size() > 0) { List<String> columnValueStrings = new ArrayList<String>(); List<Integer> columnValueIds = new ArrayList<Integer>(); for (ColumnValue columnValue : columnHeader.getColumnValues()) { columnValueStrings.add(columnValue.getValue()); columnValueIds.add(columnValue.getId()); } FormSpinner formSpinner = new FormSpinner(getActivity(), columnHeader.getColumnName(), columnValueStrings, columnValueIds); formSpinner.setReturnType(FormWidget.SCHEMA_KEY_CODEVALUE); formWidgets.add(formSpinner); linearLayout.addView(formSpinner.getView()); } } else if (columnHeader.getColumnDisplayType().equals(FormWidget.SCHEMA_KEY_DATE)) { FormEditText formEditText = new FormEditText(getActivity(), columnHeader.getColumnName()); formEditText.setIsDateField(true, getActivity().getSupportFragmentManager()); formWidgets.add(formEditText); linearLayout.addView(formEditText.getView()); } else if (columnHeader.getColumnDisplayType().equals(FormWidget.SCHEMA_KEY_BOOL)) { FormToggleButton formToggleButton = new FormToggleButton(getActivity(), columnHeader.getColumnName()); formWidgets.add(formToggleButton); linearLayout.addView(formToggleButton.getView()); } } } listFormWidgets.add(formWidgets); }