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.mozhuowen.widget.views.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {
    //?,/*from   w w w. ja va2  s. c  o m*/
    if (title.contains("$")) {
        String[] str = title.split("\\$");
        addTextTab(position, str[0], str[1]);
        isDoubleLayerInfo[position] = true;
        return;
    }

    isDoubleLayerInfo[position] = false;
    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    addTab(position, tab);
}

From source file:com.landenlabs.all_devtool.IconBaseFragment.java

/**
 * Show a 'LayerDrawable'  information./*  ww  w.  j  a v a 2  s  .  c  o m*/
 *
 * @param imageView
 * @param row1
 * @param row2
 * @param iconD
 * @param layerIdx
 */
private void showLayerIcon(final ImageView imageView, TableRow row1, TableRow row2, Drawable iconD,
        int layerIdx) {

    if (iconD != null) {
        ImageView layerImageView = new ImageView(imageView.getContext());

        layerImageView.setImageDrawable(iconD);
        layerImageView.setPadding(10, 10, 10, 10);
        layerImageView.setMinimumHeight(8);
        layerImageView.setMinimumWidth(8);
        layerImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView.setImageDrawable(((ImageView) v).getDrawable());
            }
        });

        TextView stateTextView = new TextView(imageView.getContext());
        stateTextView.setText(String.valueOf(layerIdx));
        stateTextView.setTextSize(12);
        stateTextView.setGravity(Gravity.CENTER);

        row1.addView(stateTextView);
        row2.addView(layerImageView);
    }
}

From source file:com.ab.view.sliding.AbSlidingTabView2.java

/**
 * /* w  ww  .ja  v a  2s  .  c o  m*/
 * ??tab
 * @throws 
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    Log.d(TAG, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:com.anjuke.library.uicomponent.slidingtab.PagerSlidingTabStrip.java

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

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

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tab);
}

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

private void addTextIconTab(final int position, String title, int resId) {

    if (resId == TitleIconTabProvider.NONE_ICON) {
        addTextTab(position, title);/*ww  w  . j av  a  2s .  c  o m*/
        return;
    }

    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    ImageView icon = new ImageView(getContext());
    icon.setImageResource(resId);

    LinearLayout linearLayout = new LinearLayout(getContext());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    linearLayout.addView(tab, defaultTabLayoutParams);
    linearLayout.addView(icon, defaultTabLayoutParams);

    addTab(position, linearLayout);
}

From source file:com.astuetz.PagerSlidingTitleIconTabStrip.java

private void addTextIconTab(final int position, String title, int resId) {

    if (resId == TitleIconTabProvider.NONE_ICON) {
        addTextTab(position, title);/*from  www .  j  ava  2  s  . co  m*/
        return;
    }

    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    ImageView icon = new ImageView(getContext());
    icon.setImageResource(resId);

    LinearLayout linearLayout = new LinearLayout(getContext());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    linearLayout.addView(icon, defaultTabLayoutParams);
    linearLayout.addView(tab, defaultTabLayoutParams);

    addTab(position, linearLayout);
}

From source file:com.cmax.bodysheild.widget.PagerSlidingTabStripExtends.java

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

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

    addTab(position, tab);
}

From source file:com.mozhuowen.widget.views.PagerSlidingTabStrip.java

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

    LinearLayout tab = new LinearLayout(getContext());
    tab.setGravity(Gravity.CENTER);// www . j  av  a2  s.  c  om
    tab.setOrientation(LinearLayout.VERTICAL);

    TextView titletext = new TextView(getContext());
    titletext.setText(title);
    titletext.setGravity(Gravity.CENTER);
    titletext.setSingleLine();

    TextView contenttext = new TextView(getContext());
    contenttext.setText(content);
    contenttext.setGravity(Gravity.CENTER);
    contenttext.setSingleLine();

    tab.addView(titletext);
    tab.addView(contenttext);

    addTab(position, tab);
}

From source file:com.grepsound.views.PagerSlidingTabStrip.java

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

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

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}

From source file:cn.com.incito.driver.UI.detailDialog.PagerSlidingTabStrip.java

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

    TextView tab = new TextView(getContext());
    tab.setText(title);/* ww  w.j a  v  a2 s  .c  o  m*/
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1));
    tab.setSingleLine();

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}