Example usage for android.view Gravity CENTER_HORIZONTAL

List of usage examples for android.view Gravity CENTER_HORIZONTAL

Introduction

In this page you can find the example usage for android.view Gravity CENTER_HORIZONTAL.

Prototype

int CENTER_HORIZONTAL

To view the source code for android.view Gravity CENTER_HORIZONTAL.

Click Source Link

Document

Place object in the horizontal center of its container, not changing its size.

Usage

From source file:bottombar.BottomBarTab.java

void prepareLayout() {
    inflate(getContext(), getLayoutResource(), this);
    setOrientation(VERTICAL);//from  w  w  w  . j a  v a2 s  . com
    setGravity(Gravity.CENTER_HORIZONTAL);
    setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    iconView = (AppCompatImageView) findViewById(R.id.bb_bottom_bar_icon);
    iconView.setImageResource(iconResId);

    if (type != Type.TABLET) {
        titleView = (TextView) findViewById(R.id.bb_bottom_bar_title);
        updateTitle();
    }

    updateCustomTextAppearance();
    updateCustomTypeface();
}

From source file:com.example.android.supportv7.app.ToolbarDisplayOptions.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;/*from   ww  w.j ava2  s .c om*/
    case R.id.toggle_show_home:
        flags = ActionBar.DISPLAY_SHOW_HOME;
        break;
    case R.id.toggle_use_logo:
        flags = ActionBar.DISPLAY_USE_LOGO;
        getSupportActionBar().setLogo(R.drawable.ic_media_play);
        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.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:io.engx.gitty.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/*  ww w  .  j  a va  2  s.c  om*/

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);
    mTabStrip.setGravity(Gravity.CENTER_HORIZONTAL);

    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}

From source file:org.telegram.ui.ChangePhoneHelpActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    TLRPC.User user = UserConfig.getCurrentUser();
    String value;/*  w  ww.  j a v a  2s.co m*/
    if (user != null && user.phone != null && user.phone.length() != 0) {
        value = PhoneFormat.getInstance().format("+" + user.phone);
    } else {
        value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
    }

    actionBar.setTitle(value);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new RelativeLayout(context);
    fragmentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    RelativeLayout relativeLayout = (RelativeLayout) fragmentView;

    ScrollView scrollView = new ScrollView(context);
    relativeLayout.addView(scrollView);
    RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    scrollView.setLayoutParams(layoutParams3);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20));
    scrollView.addView(linearLayout);
    ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
    layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
    layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
    linearLayout.setLayoutParams(layoutParams);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.phone_change);
    linearLayout.addView(imageView);
    LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    imageView.setLayoutParams(layoutParams2);

    TextView textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    //textView.setTextColor(0xff212121);

    try {
        textView.setText(AndroidUtilities
                .replaceTags(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)));
    } catch (Exception e) {
        FileLog.e("tmessages", e);
        textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp));
    }
    linearLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams2.leftMargin = AndroidUtilities.dp(20);
    layoutParams2.rightMargin = AndroidUtilities.dp(20);
    layoutParams2.topMargin = AndroidUtilities.dp(56);
    textView.setLayoutParams(layoutParams2);

    textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    textView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent) /*0xff4d83b3*/);
    textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange));
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16),
            AndroidUtilities.dp(12));
    textView.setBackground(context.getDrawable(R.drawable.list_selector));
    linearLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams2.leftMargin = AndroidUtilities.dp(20);
    layoutParams2.rightMargin = AndroidUtilities.dp(20);
    layoutParams2.topMargin = AndroidUtilities.dp(46);
    textView.setLayoutParams(layoutParams2);

    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            presentFragment(new ChangePhoneActivity(), true);
                        }
                    });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        }
    });

    return fragmentView;
}

From source file:org.openmrs.mobile.activities.fragments.FormPageFragment.java

void addSection(Section section, LinearLayout parent) {
    LinearLayout sectionLL = new LinearLayout(getActivity());
    sectionLL.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    //get resources

    Resources r = getActivity().getResources();
    float pxLeftMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
    float pxTopMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
    float pxRightMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
    float pxBottomMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());

    layoutParams.setMargins(Math.round(pxLeftMargin), Math.round(pxTopMargin), Math.round(pxRightMargin),
            Math.round(pxBottomMargin));

    parent.addView(sectionLL);/*  w  w w .j  a  va 2 s .  c  o m*/
    TextView tv = new TextView(getActivity());
    tv.setText(section.getLabel());
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
    tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary));
    sectionLL.addView(tv, layoutParams);

    for (Question question : section.getQuestions()) {
        addQuestion(question, sectionLL);
    }

}

From source file:com.androidzeitgeist.webcards.overlay.HandleView.java

void addToRoot() {
    setVisibility(View.VISIBLE);/* ww w  .  j  a  va 2s. co m*/

    if (isShown()) {
        return;
    }

    int size = getResources().getDimensionPixelSize(R.dimen.overlay_button_size);

    WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(size, size,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
            PixelFormat.TRANSLUCENT);

    layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.END;
    layoutParams.x = openOffsetX;

    try {
        windowManager.addView(this, layoutParams);
    } catch (final SecurityException | WindowManager.BadTokenException e) {
        // We do not have the permission to add a view to the window ("draw over other apps")
        Toast.makeText(getContext(), R.string.toast_missing_permission, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.yjx.cnblog.view.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);//from  w  ww  .j  av a 2  s .c om

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    mTabStrip.setGravity(Gravity.CENTER_HORIZONTAL);
}

From source file:com.guess.license.plate.Task.LoadingTaskConn.java

@Override
protected void onPostExecute(ServerError result) {
    super.onPostExecute(result);
    loadingDialog.dismiss();//from  w ww. ja va 2 s  .c o m

    if (result != null && !result.equals(ServerError.NO_ERROR)) {
        Toast toast = Toast.makeText(context, Language.GetServerErrorLanguage(result, context),
                Toast.LENGTH_LONG);
        toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        toast.show();
    }

    new CountDownTimer(TIMER, 1000) {

        public void onTick(long millisUntilFinished) {
            // Do nothing
        }

        public void onFinish() {
            activity.onTaskFinished();
        }
    }.start();
}

From source file:com.roughike.bottombar.BottomBarTab.java

void prepareLayout() {
    inflate(getContext(), getLayoutResource(), this);
    setOrientation(VERTICAL);/*from ww  w  .  j a v  a 2s.  c  o  m*/
    setGravity(isTitleless ? Gravity.CENTER : Gravity.CENTER_HORIZONTAL);
    setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    setBackgroundResource(MiscUtils.getDrawableRes(getContext(), R.attr.selectableItemBackgroundBorderless));

    iconView = (AppCompatImageView) findViewById(R.id.bb_bottom_bar_icon);
    iconView.setImageResource(iconResId);

    if (type != Type.TABLET && !isTitleless) {
        titleView = (TextView) findViewById(R.id.bb_bottom_bar_title);
        titleView.setVisibility(VISIBLE);

        if (type == Type.SHIFTING) {
            findViewById(R.id.spacer).setVisibility(VISIBLE);
        }

        updateTitle();
    }

    updateCustomTextAppearance();
    updateCustomTypeface();
}

From source file:nz.al4.airclock.AirClockFragment.java

private View setupClock() {
    // add digital clock
    textClock = new TextClock(getContext());
    textClock.setId(textClockId);/*  ww w  .j  a v  a 2 s.c o m*/

    textClock.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT));
    textClock.setTypeface(textClock.getTypeface(), Typeface.BOLD);
    textClock.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 48);
    textClock.setGravity(Gravity.CENTER_HORIZONTAL);

    return textClock;
}