Example usage for android.widget TextView setGravity

List of usage examples for android.widget TextView setGravity

Introduction

In this page you can find the example usage for android.widget TextView setGravity.

Prototype

public void setGravity(int gravity) 

Source Link

Document

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.

Usage

From source file:com.jianghua.viewpagerwithhead.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);//from ww  w.  java2s  .  c o m
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    //Jobs
    if (position == 0) {
        tab.setTextColor(getContext().getResources().getColor(R.color.green));
        tab.setTextSize(tabPressedTextSize);
    } else {
        tab.setTextColor(getContext().getResources().getColor(R.color.black));
        tab.setTextSize(tabTextSize);
    }
    addTab(position, tab);
}

From source file:com.google.android.apps.flexbox.MainActivity.java

private TextView createBaseFlexItemTextView(int index) {
    TextView textView = new TextView(this);
    textView.setBackgroundResource(R.drawable.flex_item_background);
    textView.setText(String.valueOf(index + 1));
    textView.setGravity(Gravity.CENTER);
    return textView;
}

From source file:com.juma.view.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);//from   ww  w  . java2s .c o  m
    tab.setGravity(Gravity.CENTER);
    tab.setTextColor(tabTextColor);
    tab.setSingleLine();

    addTab(position, tab);
}

From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    if (mLeftViewId != 0 && mSwipeLeftHorizontal == null) {
        View view = findViewById(mLeftViewId);
        mSwipeLeftHorizontal = new SwipeLeftHorizontal(view);
    }//w w  w. ja v a  2  s .  c  o  m
    if (mRightViewId != 0 && mSwipeRightHorizontal == null) {
        View view = findViewById(mRightViewId);
        mSwipeRightHorizontal = new SwipeRightHorizontal(view);
    }
    if (mContentViewId != 0 && mContentView == null) {
        mContentView = findViewById(mContentViewId);
    } else {
        TextView errorView = new TextView(getContext());
        errorView.setClickable(true);
        errorView.setGravity(Gravity.CENTER);
        errorView.setTextSize(16);
        errorView.setText("You may not have set the ContentView.");
        mContentView = errorView;
        addView(mContentView);
    }
}

From source file:com.dashihui.afford.ui.widget.WdtPagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);//from w  w w. ja v  a  2 s .c  om
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    addTab(position, tab);
    mTextViewMap.put(position, tab);
}

From source file:com.icoder.couldnewsclient.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);//from   w ww .  j  av a 2s  .c o m
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    //
    if (position == 0) {
        selectedTabText = tab;
    }

    addTab(position, tab);
}

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout ActivateColorize(LinearLayout ll, String text, Drawable dr) {

    // text/*from   w w  w.  j a v  a2s  .c o  m*/
    TextView v = (TextView) ll.findViewWithTag("tv");
    v.setText(text);
    v.setTextSize(10);
    v.setTextColor(Color.BLACK); //v.setTextColor(Color.WHITE);
    v.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    //dr.setColorFilter(0xFF888888, android.graphics.PorterDuff.Mode.MULTIPLY);
    dr.setColorFilter(resources.getColor(R.color.orange), android.graphics.PorterDuff.Mode.SRC_ATOP);

    v.setCompoundDrawablesWithIntrinsicBounds(null, dr, null, null);
    v.setPadding(0, 5, 0, 2);

    v.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_tabs_focused));

    // hbar
    View hbar = ll.findViewWithTag("hbar");
    //hbar.setBackgroundColor(resources.getColor(R.color.orange));
    hbar.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_orange));

    return ll;
}

From source file:com.honeywell.printer.indicator.TabPageIndicator.java

/**
 * ?//  www  .  j  a v  a2s  .  c om
 *
 * @param index tab
 * @param count ?
 */
public void showTabMsgCountView(int index, int count, int res) {
    if (mTabLayout != null) {
        final TextView msgCountView = (TextView) mTabLayout.findViewById(index + ID_OFFSET);
        if (msgCountView != null) {
            final int color = getResources().getColor(R.color.new_msg_num_text_color);
            msgCountView.setTextColor(color);
            msgCountView.setGravity(Gravity.CENTER);
            msgCountView.setTypeface(Typeface.DEFAULT_BOLD);
            // final int paddingPixels = Tools.dp2px(2);
            int paddingPixels = (int) getResources().getDimension(R.dimen.indicator_num_padding);
            msgCountView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
            final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            final int badgeMarginLeft = (int) getResources().getDimension(R.dimen.indicator_marginleft);
            final int badgeMarginBottom = (int) getResources().getDimension(R.dimen.indicator_marginbottom);
            params.gravity = Gravity.CENTER;
            params.setMargins(badgeMarginLeft, 0, 0, badgeMarginBottom);
            if (count == 0) {
                msgCountView.setVisibility(View.GONE);
                return;
            } else if (count > 99) {
                msgCountView.setText("99+");
                msgCountView.setBackgroundResource(R.drawable.tab_msg_num_big_bg);
            } else {
                msgCountView.setText(String.valueOf(count));
                msgCountView.setBackgroundResource(res);
            }
            msgCountView.setTextSize(11);
            msgCountView.setLayoutParams(params);
            msgCountView.setVisibility(View.VISIBLE);
        }

    }
}

From source file:com.example.appdetail_optimization.PagerSlidingTabStrip.java

@SuppressWarnings("deprecation")
private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);//from  w  ww.  j  a v  a2 s  .  c  o  m
    tab.setGravity(Gravity.CENTER);
    tab.setPadding(0, 0, 0, 0);

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    int width = wm.getDefaultDisplay().getWidth();
    tab.setMaxWidth(width / tabCount - tabPadding * 2);
    tab.setEllipsize(TruncateAt.END);
    tab.setSingleLine();
    addTab(position, tab);
}

From source file:com.dudu.duduhelper.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);/*from w  w  w.  ja  va 2 s. co  m*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    addTab(position, tab);
    //      MessageButton tab=new MessageButton(getContext());
    //      tab.setText(title);
    //      if(TextUtils.isEmpty(num))
    //      {
    //         tab.setVisibility(View.GONE);
    //      }
    //      tab.setNum(num);
    //      addTab(position, tab);
}