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:com.brookmanholmes.bma.wizard.ui.StepPagerStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (pageCount == 0) {
        return;/*from w  w  w  . j a  v a 2s .c  o  m*/
    }

    float totalWidth = pageCount * (tabWidth + indicatorSpacing) - indicatorSpacing;
    float totalcx;
    float cy;
    boolean fillHorizontal = false;

    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        totalcx = (getWidth() - totalWidth) / 2;
        break;
    case Gravity.RIGHT:
        totalcx = getWidth() - getPaddingRight() - totalWidth;
        break;
    case Gravity.FILL_HORIZONTAL:
        totalcx = getPaddingLeft();
        fillHorizontal = true;
        break;
    default:
        totalcx = getPaddingLeft();
    }

    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.CENTER_VERTICAL:
        cy = (int) (getHeight() - tabHeight) / 2;
        break;
    case Gravity.BOTTOM:
        cy = getHeight() - getPaddingBottom() - tabHeight;
        break;
    default:
        cy = getPaddingTop();
    }

    float center = cy + tabHeight / 2;

    float tabWidth = this.tabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (pageCount - 1) * indicatorSpacing)
                / pageCount;
    }

    for (int i = 0; i < pageCount; i++) {
        float cx = totalcx + (i * (tabWidth + indicatorSpacing));

        Paint tempPaint;

        if (i < currentPage)
            tempPaint = prevTabPaint;
        else if (i > currentPage)
            tempPaint = nextTabPaint;
        else
            tempPaint = selectedTabPaint;

        canvas.drawCircle(cx, center, i == currentPage ? radius : nonCurrentRadius, tempPaint);
    }
}

From source file:rs.pedjaapps.kerneltuner.ui.BuildpropEditor.java

@Override
public void onCreate(Bundle savedInstanceState) {
    entries = new ArrayList<>();
    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.build);/*www  .j a va2s  .  c o  m*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    bListView = (ListView) findViewById(R.id.list);
    bAdapter = new BuildAdapter(this, new ArrayList<Build>());
    bListView.setAdapter(bAdapter);

    bListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View v, final int pos, long is) {
            AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
            final Build build = bAdapter.getItem(pos);
            builder.setTitle(build.key);

            builder.setIcon(R.drawable.build);

            final EditText input = new EditText(v.getContext());
            input.setText(build.value);
            input.selectAll();
            input.setGravity(Gravity.CENTER_HORIZONTAL);
            input.requestFocus();

            builder.setPositiveButton(getString(R.string.Change), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    build.value = input.getText().toString().trim();
                    saveBuildProp(build);
                }
            });
            builder.setNegativeButton(getResources().getString(R.string.cancel), null);
            builder.setView(input);

            AlertDialog alert = builder.create();

            alert.show();
        }
    });
    new GetBuildEntries().execute();
}

From source file:de.vanita5.twittnuker.view.ProfileImageBannerLayout.java

@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    final int width = MeasureSpec.getSize(widthMeasureSpec), height = width / 2;
    setMeasuredDimension(width, height);
    super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
    if (width > 0) {
        final int profile_size = (int) (width * PROFILE_IMAGE_WIDTH_FACTOR);
        final LayoutParams profile_lp = (FrameLayout.LayoutParams) mProfileImageView.getLayoutParams();
        profile_lp.width = profile_size + mBorderWidth * 2;
        profile_lp.height = profile_size + mBorderWidth * 2;
        profile_lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
        profile_lp.topMargin = (int) (height * PROFILE_IMAGE_TOP_MARGIN_FACTOR) - mBorderWidth;
        mProfileImageView.setLayoutParams(profile_lp);
    }/*  ww  w .  j a va2 s .co  m*/
}

From source file:com.ntsync.android.sync.activities.AccountListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Context context = view.getContext();
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);

    Button loginBtn = new Button(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);//www  .ja va2s  .c o  m
    layoutParams.rightMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            view.getResources().getDisplayMetrics());
    loginBtn.setLayoutParams(layoutParams);
    loginBtn.setText(context.getResources().getText(R.string.accountlist_login_button));
    loginBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            startLoginView();
        }
    });

    Button createAccountBtn = new Button(context);
    createAccountBtn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    createAccountBtn.setText(context.getResources().getText(R.string.accountlist_creataccount_button));
    createAccountBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            createAccountView();
        }
    });

    linearLayout.addView(loginBtn);
    linearLayout.addView(createAccountBtn);
    ((ViewGroup) this.getListView().getParent()).addView(linearLayout);
    this.getListView().setEmptyView(linearLayout);
}

From source file:org.yammp.fragment.LyricsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    mInterface = ((YAMMPApplication) getSherlockActivity().getApplication()).getServiceInterface();
    super.onActivityCreated(savedInstanceState);
    mSearchFragment = new LyricsSearchFragment();
    getFragmentManager().addOnBackStackChangedListener(this);
    View view = getView();// ww  w .j  a va 2 s  .c  o  m
    mLyricsScrollView = (TextScrollView) view.findViewById(R.id.lyrics_scroll);
    mLyricsScrollView.setContentGravity(Gravity.CENTER_HORIZONTAL);
    mLyricsScrollView.setLineSelectedListener(this);
    mLyricsEmptyView = (Button) view.findViewById(R.id.lyrics_empty);
    mLyricsEmptyView.setOnClickListener(this);
    mLyricsSearchLayout = (LinearLayout) view.findViewById(R.id.search_lyrics);
    mInterface.addLyricsStateListener(this);
}

From source file:com.vonglasow.michael.satstat.GpsSectionFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) this.getContext();
    View rootView = inflater.inflate(R.layout.fragment_main_gps, container, false);

    // Initialize controls
    gpsRootLayout = (LinearLayout) rootView.findViewById(R.id.gpsRootLayout);
    gpsSnrView = (GpsSnrView) rootView.findViewById(R.id.gpsSnrView);
    gpsStatusView = new GpsStatusView(rootView.getContext());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);// w  ww.j ava  2s. co  m
    params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
    params.weight = 1;
    gpsRootLayout.addView(gpsStatusView, 0, params);
    gpsLatLayout = (LinearLayout) rootView.findViewById(R.id.gpsLatLayout);
    gpsLat = (TextView) rootView.findViewById(R.id.gpsLat);
    gpsLonLayout = (LinearLayout) rootView.findViewById(R.id.gpsLonLayout);
    gpsLon = (TextView) rootView.findViewById(R.id.gpsLon);
    gpsCoordLayout = (LinearLayout) rootView.findViewById(R.id.gpsCoordLayout);
    gpsCoord = (TextView) rootView.findViewById(R.id.gpsCoord);
    orDeclination = (TextView) rootView.findViewById(R.id.orDeclination);
    gpsSpeed = (TextView) rootView.findViewById(R.id.gpsSpeed);
    gpsSpeedUnit = (TextView) rootView.findViewById(R.id.gpsSpeedUnit);
    gpsAlt = (TextView) rootView.findViewById(R.id.gpsAlt);
    gpsAltUnit = (TextView) rootView.findViewById(R.id.gpsAltUnit);
    gpsTime = (TextView) rootView.findViewById(R.id.gpsTime);
    gpsBearing = (TextView) rootView.findViewById(R.id.gpsBearing);
    gpsAccuracy = (TextView) rootView.findViewById(R.id.gpsAccuracy);
    gpsAccuracyUnit = (TextView) rootView.findViewById(R.id.gpsAccuracyUnit);
    gpsOrientation = (TextView) rootView.findViewById(R.id.gpsOrientation);
    gpsSats = (TextView) rootView.findViewById(R.id.gpsSats);
    gpsTtff = (TextView) rootView.findViewById(R.id.gpsTtff);

    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT);

    mainActivity.gpsSectionFragment = this;

    return rootView;
}

From source file:id.co.datascrip.dtswarehousesystem.custom.StepPagerStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mPageCount == 0) {
        return;/*  www .j  av a 2  s  .  c o m*/
    }

    float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
    float totalLeft;
    boolean fillHorizontal = false;

    switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        totalLeft = (getWidth() - totalWidth) / 2;
        break;
    case Gravity.END:
        totalLeft = getWidth() - getPaddingRight() - totalWidth;
        break;
    case Gravity.FILL_HORIZONTAL:
        totalLeft = getPaddingLeft();
        fillHorizontal = true;
        break;
    default:
        totalLeft = getPaddingLeft();
    }

    switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.CENTER_VERTICAL:
        mTempRectF.top = (int) (getHeight() - mTabHeight) / 2;
        break;
    case Gravity.BOTTOM:
        mTempRectF.top = getHeight() - getPaddingBottom() - mTabHeight;
        break;
    default:
        mTempRectF.top = getPaddingTop();
    }

    mTempRectF.bottom = mTempRectF.top + mTabHeight;

    float tabWidth = mTabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (mPageCount - 1) * mTabSpacing)
                / mPageCount;
    }

    for (int i = 0; i < mPageCount; i++) {
        mTempRectF.left = totalLeft + (i * (tabWidth + mTabSpacing));
        mTempRectF.right = mTempRectF.left + tabWidth;
        canvas.drawRect(mTempRectF,
                i < mCurrentPage ? mPrevTabPaint
                        : (i > mCurrentPage ? mNextTabPaint
                                : (i == mPageCount - 1 ? mSelectedLastTabPaint : mSelectedTabPaint)));
    }
}

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

void prepareLayout() {
    int layoutResource;

    layoutResource = getLayoutResource();

    inflate(getContext(), layoutResource, this);
    setOrientation(VERTICAL);/*from  ww  w . jav  a 2s.co m*/
    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);
        titleView.setText(title);
    }

    updateCustomTextAppearance();
    updateCustomTypeface();
}

From source file:com.community.yuequ.bottombar.BottomBarTab.java

void prepareLayout() {
    int layoutResource;

    layoutResource = getLayoutResource();

    inflate(getContext(), layoutResource, this);
    setOrientation(VERTICAL);/*from w w  w .j a va  2 s .co m*/
    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);
        titleView.setText(title);
    }

    updateCustomTextAppearance();
    updateCustomTypeface();
}

From source file:com.example.tt.pullrefresh.widget.SwipItemLayout.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  ww  . ja va2 s .  c  om
    sheet = child;
    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);
}