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.hyperkode.friendshare.fragment.LoginFragment.java
private void setupButtons() { // Login button handler loginButton = (Button) mThisActivity.findViewById(R.id.loginbutton_continue); loginButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { EditText usernameText = (EditText) mThisActivity.findViewById(R.id.login_username_textbox); String un = usernameText.getText().toString(); if (cb != null && cb.isChecked()) { // do Twitter login authTwitter();//from w ww . j a v a 2 s. c o m return; } if (un == null || un.length() == 0) { Toast toast = Toast.makeText(mThis, mThis.getString(R.string.enter_username), Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0); toast.show(); return; } //EditText passwordText = (EditText) findViewById(R.id.login_password_textbox); //String pw = passwordText.getText().toString(); //Intent i = new Intent(mThis, LandingActivity.class); //mThis.startActivity(i); /* FragmentManager fm = LoginFragment.this.getActivity().getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.main_view_containter, LoginFragment.this); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.addToBackStack(null); ft.commit(); */ } }); // Cancel button handler cancelButton = (Button) mThisActivity.findViewById(R.id.loginbutton_cancel); cancelButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Exit screen mThis.finish(); } }); }
From source file:com.xargsgrep.portknocker.asynctask.KnockerAsyncTask.java
private void showToast(String text) { Toast toast = Toast.makeText(activity, text, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); }
From source file:com.simas.vc.file_chooser.FileChooser.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); // Make the window always appear on the top of the screen try {/*from w w w .jav a 2 s .c o m*/ WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(getDialog().getWindow().getAttributes()); lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; getDialog().getWindow().setAttributes(lp); } catch (NullPointerException e) { Log.e(TAG, "Failed to set FileChooser window gravity!", e); } return view; }
From source file:com.tmall.wireless.tangram.view.LinearScrollView.java
private void init() { setGravity(Gravity.CENTER_HORIZONTAL); setOrientation(VERTICAL);/*from w w w . java2s . c o m*/ inflate(getContext(), R.layout.tangram_linearscrollview, this); setClickable(true); recyclerView = (RecyclerView) findViewById(R.id.tangram_linearscrollview_container); indicator = findViewById(R.id.tangram_linearscrollview_indicator); indicatorContainer = findViewById(R.id.tangram_linearscrollview_indicator_container); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); layoutManager.setOrientation(HORIZONTAL); layoutManager.setRecycleChildrenOnDetach(true); recyclerView.setLayoutManager(layoutManager); totalDistanceOfIndicator = Style.dp2px(34); touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); overScrollDecorator = new HorizontalOverScrollBounceEffectDecoratorExt( new StaticOverScrollDecorAdapter(this)); }
From source file:com.example.android.supportv7.app.ActionBarDisplayOptions.java
@Override public void onClick(View v) { final ActionBar bar = getSupportActionBar(); int flags = 0; switch (v.getId()) { case R.id.toggle_home_as_up: flags = ActionBar.DISPLAY_HOME_AS_UP; break;/* w w w . j a v a2 s. c o m*/ case R.id.toggle_show_home: flags = ActionBar.DISPLAY_SHOW_HOME; break; case R.id.toggle_use_logo: flags = ActionBar.DISPLAY_USE_LOGO; break; case R.id.toggle_show_title: flags = ActionBar.DISPLAY_SHOW_TITLE; break; case R.id.toggle_show_custom: flags = ActionBar.DISPLAY_SHOW_CUSTOM; break; case R.id.toggle_navigation: bar.setNavigationMode( bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD ? ActionBar.NAVIGATION_MODE_TABS : ActionBar.NAVIGATION_MODE_STANDARD); return; case R.id.cycle_custom_gravity: { ActionBar.LayoutParams lp = mCustomViewLayoutParams; int newGravity = 0; switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: newGravity = Gravity.CENTER_HORIZONTAL; break; case Gravity.CENTER_HORIZONTAL: newGravity = Gravity.RIGHT; break; case Gravity.RIGHT: newGravity = Gravity.LEFT; break; } lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity; bar.setCustomView(mCustomView, lp); return; } case R.id.toggle_visibility: if (bar.isShowing()) { bar.hide(); } else { bar.show(); } return; } int change = bar.getDisplayOptions() ^ flags; bar.setDisplayOptions(change, flags); }
From source file:com.miqtech.master.client.view.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);//w w w. j ava 2 s. co m setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setGravity(Gravity.CENTER_HORIZONTAL); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams tabsContainerParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); tabsContainer.setLayoutParams(tabsContainerParams); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(0, tabTextSize); tabTextColor = a.getColor(1, tabTextColor); a.recycle(); // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } ScrollController.addViewPager(getClass().getSimpleName(), this); }
From source file:pl.bcichecki.rms.client.android.dialogs.RegisterDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { context = getActivity();//from w w w .j ava2s . c o m AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(getString(R.string.dialog_register_title)); builder.setMessage(getString(R.string.dialog_register_message)); final EditText usernameEditText = new EditText(getActivity()); usernameEditText.setHint(getString(R.string.dialog_register_enter_username_hint)); usernameEditText.setMaxLines(1); usernameEditText.setSingleLine(); usernameEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT); usernameEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { usernameEditText.setError(null); } }); final EditText passwordEditText = new EditText(getActivity()); passwordEditText.setHint(getString(R.string.dialog_register_enter_password_hint)); passwordEditText.setMaxLines(1); passwordEditText.setSingleLine(); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT); passwordEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { passwordEditText.setError(null); } }); final EditText emailEditText = new EditText(getActivity()); emailEditText.setHint(getString(R.string.dialog_register_enter_email_hint)); emailEditText.setMaxLines(1); emailEditText.setSingleLine(); emailEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); emailEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { emailEditText.setError(null); } }); final LinearLayout layout = new LinearLayout(getActivity()); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.CENTER_HORIZONTAL); int space = (int) AppUtils.convertDpToPixel(getActivity(), 16); layout.setPadding(space, 0, space, 0); layout.addView(usernameEditText); layout.addView(passwordEditText); layout.addView(emailEditText); builder.setView(layout); builder.setPositiveButton(getString(R.string.dialog_register_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { return; } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { return; } }); final AlertDialog dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { utilitiesRestClient = new UtilitiesRestClient(getActivity(), SharedPreferencesWrapper.getServerAddress(), SharedPreferencesWrapper.getServerPort(), SharedPreferencesWrapper.getWebserviceContextPath()); final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!AppUtils.checkInternetConnection(getActivity())) { Log.d(TAG, "There is NO network connected!"); return; } usernameEditText.setError(null); passwordEditText.setError(null); emailEditText.setError(null); if (StringUtils.isBlank(usernameEditText.getText().toString())) { usernameEditText.setError(getString(R.string.dialog_register_field_required)); return; } if (StringUtils.isBlank(passwordEditText.getText().toString())) { passwordEditText.setError(getString(R.string.dialog_register_field_required)); return; } if (StringUtils.isBlank(emailEditText.getText().toString())) { emailEditText.setError(getString(R.string.dialog_register_field_required)); return; } if (!AppUtils.validateEmail(emailEditText.getText().toString())) { emailEditText.setError(getString(R.string.dialog_register_email_not_valid)); return; } final User user = new User(); user.setUsername(usernameEditText.getText().toString()); user.setPassword(SecurityUtils.hashSHA512Base64(passwordEditText.getText().toString())); user.setEmail(StringUtils.lowerCase(emailEditText.getText().toString())); user.setAddress(new AddressData()); utilitiesRestClient.registerUser(user, new AsyncHttpResponseHandler() { @Override public void onFailure(Throwable error, String content) { Log.d(TAG, "Registering user failed. [error= " + error + ", content=" + content + "]"); AppUtils.showCenteredToast(context, getString(R.string.dialog_register_failed), Toast.LENGTH_LONG); } @Override public void onFinish() { positiveButton.setEnabled(true); } @Override public void onStart() { Log.d(TAG, "Registering user: " + user.toString()); AppUtils.showCenteredToast(context, getString(R.string.dialog_register_in_progress), Toast.LENGTH_SHORT); positiveButton.setEnabled(false); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Registered user successfully."); AppUtils.showCenteredToast(context, getString(R.string.dialog_register_successful), Toast.LENGTH_SHORT); SharedPreferencesWrapper.setUsername(user.getUsername()); SharedPreferencesWrapper.setPasswordHash(user.getPassword()); SharedPreferencesWrapper.setRememberUser(true); dialog.dismiss(); } }); } }); final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); negativeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cancelRequests(); dialog.dismiss(); } }); } }); return dialog; }
From source file:com.amitupadhyay.aboutexample.ui.widget.BottomSheet.java
@Override public void addView(View child, int index, ViewGroup.LayoutParams params) { if (sheet != null) { throw new UnsupportedOperationException("BottomSheet must only have 1 child view"); }/*from www.ja va2s.c o m*/ 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:com.forrestguice.suntimeswidget.EquinoxView.java
private void init(Context context, AttributeSet attrs) { initLocale(context);// w ww. j a v a 2 s.c om initColors(context); LayoutInflater.from(context).inflate(R.layout.layout_view_equinox, this, true); if (attrs != null) { LinearLayout.LayoutParams lp = generateLayoutParams(attrs); centered = ((lp.gravity == Gravity.CENTER) || (lp.gravity == Gravity.CENTER_HORIZONTAL)); } empty = (TextView) findViewById(R.id.txt_empty); flipper = (ViewFlipper) findViewById(R.id.info_equinoxsolstice_flipper); flipper.setOnTouchListener(cardTouchListener); notes = new ArrayList<EquinoxNote>(); RelativeLayout thisYear = (RelativeLayout) findViewById(R.id.info_equinoxsolstice_thisyear); if (thisYear != null) { btn_flipperNext_thisYear = (ImageButton) thisYear.findViewById(R.id.info_time_nextbtn); btn_flipperNext_thisYear.setOnClickListener(onNextCardClick); btn_flipperNext_thisYear.setOnTouchListener(createButtonListener(btn_flipperNext_thisYear)); btn_flipperPrev_thisYear = (ImageButton) thisYear.findViewById(R.id.info_time_prevbtn); btn_flipperPrev_thisYear.setVisibility(View.GONE); titleThisYear = (TextView) thisYear.findViewById(R.id.text_title); TextView txt_equinox_vernal_label = (TextView) thisYear .findViewById(R.id.text_date_equinox_vernal_label); TextView txt_equinox_vernal = (TextView) thisYear.findViewById(R.id.text_date_equinox_vernal); TextView txt_equinox_vernal_note = (TextView) thisYear.findViewById(R.id.text_date_equinox_vernal_note); note_equinox_vernal = addNote(txt_equinox_vernal_label, txt_equinox_vernal, txt_equinox_vernal_note, 0); TextView txt_solstice_summer_label = (TextView) thisYear .findViewById(R.id.text_date_solstice_summer_label); TextView txt_solstice_summer = (TextView) thisYear.findViewById(R.id.text_date_solstice_summer); TextView txt_solstice_summer_note = (TextView) thisYear .findViewById(R.id.text_date_solstice_summer_note); note_solstice_summer = addNote(txt_solstice_summer_label, txt_solstice_summer, txt_solstice_summer_note, 0); TextView txt_equinox_autumnal_label = (TextView) thisYear .findViewById(R.id.text_date_equinox_autumnal_label); TextView txt_equinox_autumnal = (TextView) thisYear.findViewById(R.id.text_date_equinox_autumnal); TextView txt_equinox_autumnal_note = (TextView) thisYear .findViewById(R.id.text_date_equinox_autumnal_note); note_equinox_autumnal = addNote(txt_equinox_autumnal_label, txt_equinox_autumnal, txt_equinox_autumnal_note, 0); TextView txt_solstice_winter_label = (TextView) thisYear .findViewById(R.id.text_date_solstice_winter_label); TextView txt_solstice_winter = (TextView) thisYear.findViewById(R.id.text_date_solstice_winter); TextView txt_solstice_winter_note = (TextView) thisYear .findViewById(R.id.text_date_solstice_winter_note); note_solstice_winter = addNote(txt_solstice_winter_label, txt_solstice_winter, txt_solstice_winter_note, 0); if (centered) { FrameLayout.LayoutParams lpThisYear = (FrameLayout.LayoutParams) thisYear.getLayoutParams(); lpThisYear.gravity = Gravity.CENTER_HORIZONTAL; thisYear.setLayoutParams(lpThisYear); } } RelativeLayout nextYear = (RelativeLayout) findViewById(R.id.info_equinoxsolstice_nextyear); if (nextYear != null) { btn_flipperNext_nextYear = (ImageButton) nextYear.findViewById(R.id.info_time_nextbtn); btn_flipperNext_nextYear.setVisibility(View.GONE); btn_flipperPrev_nextYear = (ImageButton) nextYear.findViewById(R.id.info_time_prevbtn); btn_flipperPrev_nextYear.setOnClickListener(onPrevCardClick); btn_flipperPrev_nextYear.setOnTouchListener(createButtonListener(btn_flipperPrev_nextYear)); titleNextYear = (TextView) nextYear.findViewById(R.id.text_title); TextView txt_equinox_vernal2_label = (TextView) nextYear .findViewById(R.id.text_date_equinox_vernal_label); TextView txt_equinox_vernal2 = (TextView) nextYear.findViewById(R.id.text_date_equinox_vernal); TextView txt_equinox_vernal2_note = (TextView) nextYear .findViewById(R.id.text_date_equinox_vernal_note); note_equinox_vernal2 = addNote(txt_equinox_vernal2_label, txt_equinox_vernal2, txt_equinox_vernal2_note, 1); TextView txt_solstice_summer2_label = (TextView) nextYear .findViewById(R.id.text_date_solstice_summer_label); TextView txt_solstice_summer2 = (TextView) nextYear.findViewById(R.id.text_date_solstice_summer); TextView txt_solstice_summer2_note = (TextView) nextYear .findViewById(R.id.text_date_solstice_summer_note); note_solstice_summer2 = addNote(txt_solstice_summer2_label, txt_solstice_summer2, txt_solstice_summer2_note, 1); TextView txt_equinox_autumnal2_label = (TextView) nextYear .findViewById(R.id.text_date_equinox_autumnal_label); TextView txt_equinox_autumnal2 = (TextView) nextYear.findViewById(R.id.text_date_equinox_autumnal); TextView txt_equinox_autumnal2_note = (TextView) nextYear .findViewById(R.id.text_date_equinox_autumnal_note); note_equinox_autumnal2 = addNote(txt_equinox_autumnal2_label, txt_equinox_autumnal2, txt_equinox_autumnal2_note, 1); TextView txt_solstice_winter2_label = (TextView) nextYear .findViewById(R.id.text_date_solstice_winter_label); TextView txt_solstice_winter2 = (TextView) nextYear.findViewById(R.id.text_date_solstice_winter); TextView txt_solstice_winter2_note = (TextView) nextYear .findViewById(R.id.text_date_solstice_winter_note); note_solstice_winter2 = addNote(txt_solstice_winter2_label, txt_solstice_winter2, txt_solstice_winter2_note, 1); if (centered) { FrameLayout.LayoutParams lpNextYear = (FrameLayout.LayoutParams) nextYear.getLayoutParams(); lpNextYear.gravity = Gravity.CENTER_HORIZONTAL; nextYear.setLayoutParams(lpNextYear); } } if (isInEditMode()) { updateViews(context, null); } }
From source file:nz.al4.airclock.AirClockFragment.java
private View setupDate() { // add digital date textDate = new TextClock(getContext()); textDate.setId(textDateId);/*from w w w . j ava 2 s . c o m*/ RelativeLayout.LayoutParams textDateParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); textDateParams.addRule(RelativeLayout.BELOW, textClockId); textDate.setLayoutParams(textDateParams); textDate.setTypeface(textDate.getTypeface(), Typeface.BOLD); textDate.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textDate.setGravity(Gravity.CENTER_HORIZONTAL); SpannableString dateSpan = new SpannableString("yyyy/MM/dd"); textDate.setFormat24Hour(dateSpan); textDate.setFormat12Hour(dateSpan); return textDate; }