Example usage for android.widget TextView setWidth

List of usage examples for android.widget TextView setWidth

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setWidth(int pixels) 

Source Link

Document

Sets the width of the TextView to be exactly pixels wide.

Usage

From source file:Main.java

protected static Bitmap creatCodeBitmap(String contents, int width, int height, Context context) {
    TextView tv = new TextView(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(layoutParams);/*from  ww  w .j  av  a  2s  .c  om*/
    tv.setText(contents);
    tv.setHeight(height);
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    tv.setWidth(width);
    tv.setDrawingCacheEnabled(true);
    tv.setTextColor(Color.BLACK);
    tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

    tv.buildDrawingCache();
    Bitmap bitmapCode = tv.getDrawingCache();
    return bitmapCode;
}

From source file:jp.gr.java_conf.ishiisoft.android.adapter.SwipeSelectorAdapter.java

/**
 * create page//  w  w  w .ja  v  a 2s.c o m
 * @param container
 * @param position
 */
@Override
public Object instantiateItem(ViewGroup container, int position) {
    // center text
    TextView centerText = new TextView(context);
    centerText.setText(textList[position]);
    centerText.setWidth(10);
    if (gravity >= 0)
        centerText.setGravity(gravity);
    if (color < 0)
        centerText.setTextColor(color);
    if (size >= 0)
        centerText.setTextSize(size);
    if (typeface != null)
        centerText.setTypeface(typeface);
    centerVp.addView(centerText, 0);

    return centerText;
}

From source file:des.calculator.ui.MenuTabActivity.java

private void buildHistoryTable() {
    final int historySize = state.getHistoryLength();

    TableRow currentRow = null;/*from   w  w  w  .ja va 2  s .  c  o m*/
    // clear the table in case it has already been loaded.
    historyTable.removeAllViews();
    // for each history entry
    for (int i = historySize - 1; i >= 0; i--) {
        // create the new row
        currentRow = new TableRow(this);
        //TableLayout.LayoutParams rowLayout = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);

        //rowLayout.setMargins(2, 2, 2, 2);
        //currentRow.setLayoutParams(rowLayout);
        //currentRow.setBackgroundColor(0xFF282828);
        currentRow.setBackgroundResource(R.layout.rowlayout);
        historyTable.addView(currentRow,
                new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        // add the history info
        TextView entry = new TextView(this);
        entry.setText(state.getInputHistory(i));
        entry.setGravity(Gravity.LEFT);
        entry.setTextSize(20);
        entry.setTextColor(0xFFFFFFFF);

        TextView answer = new TextView(this);
        answer.setText(state.getAnsHistory(i));
        answer.setGravity(Gravity.RIGHT);
        answer.setWidth(30);
        answer.setTextSize(20);
        answer.setTextColor(0xFFFFFFFF);

        // create layout params for the text views
        TableRow.LayoutParams textLayout = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        textLayout.setMargins(4, 1, 4, 1);

        currentRow.addView(entry, textLayout);
        currentRow.addView(answer, textLayout);
    }
}

From source file:org.steveleach.scoresheet.ui.PlayersFragment.java

private void addHeader(String text, TableRow headers, int width) {
    TextView view = new TextView(activity);
    view.setTextAppearance(activity, R.style.gameReportTextStyle);
    view.setText(text);/*from   w w w  .  j a  v a  2  s .  c  o m*/
    view.setWidth(width);
    headers.addView(view);
}

From source file:com.tomandfelix.stapp2.tabs.SlidingTabLayout.java

public void setLabelWidth() {
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/*  w w  w  .j a  v  a  2 s . c om*/
    for (TextView t : labels) {
        t.setWidth(size.x / 2);
    }
}

From source file:com.jeffreyawest.weblogic.monitor.charting.DefaultPieChart.java

protected final TableRow getRow(final Activity pActivity, int pColor, String pValue) {

    TableRow row = new TableRow(pActivity);
    row.setPadding(2, 2, 2, 2);// w  w  w  .  ja v  a  2  s .co  m

    pActivity.getResources().getDimension(R.dimen.graph_fragment_legend_graphic_size);

    TextView colorView = new TextView(pActivity);
    colorView.setBackgroundColor(pColor);
    colorView
            .setHeight((int) pActivity.getResources().getDimension(R.dimen.graph_fragment_legend_graphic_size));
    colorView.setText("   ");
    colorView.setWidth((int) pActivity.getResources().getDimension(R.dimen.graph_fragment_legend_graphic_size));
    row.addView(colorView);

    TextView text = new TextView(pActivity);
    text.setText(pValue);
    text.setPadding(2, 2, 2, 2);
    text.setTextSize(15);
    row.addView(text);

    return row;
}

From source file:com.funny.developers.musicstylelist.view.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from   w  ww. ja  va2  s.  com
 */
protected TextView createDefaultTabView(Context context, int tabViewWidth) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setWidth(tabViewWidth);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTextColor(mTextColor);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.zhongsou.souyue.ui.indicator.CheckTabPageIndicator.java

private void doSetTextStyle(TextView tv, int background) {
    tv.setGravity(Gravity.CENTER);//  ww w .  ja  v a2 s . c om
    tv.setBackgroundResource(background);
    tv.setPadding(10, 12, 10, 12);
    tv.setTextSize(16);
    tv.setMaxLines(1);
    tv.setWidth(dip2px(this.getContext(), 110));
    tv.setTextColor(0xff696969);
}

From source file:sliding_tab.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from  w  w  w.  j  a v a2  s.  c o  m*/
 */
protected TextView createDefaultTabView(Context context) {

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    //        int height = size.y;

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setWidth(width / numOfLayouts);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding / 2, padding, padding / 2, padding);

    return textView;
}

From source file:com.example.uidemo.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//w w  w.ja  v a2 s .c o  m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setWidth(context.getResources().getDisplayMetrics().widthPixels / 3);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}