Example usage for android.widget TextView setMaxWidth

List of usage examples for android.widget TextView setMaxWidth

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setMaxWidth(int maxPixels) 

Source Link

Document

Sets the width of the TextView to be at most maxPixels wide.

Usage

From source file:com.example.SmartBoard.DrawingView.java

public Bitmap textToBitmap(String text, int color, float posX, float posY, int size) {
    TextView textView = new TextView(getContext());
    textView.setVisibility(View.VISIBLE);
    textView.setTextColor(color);/*from  w w  w. j  a va 2 s.  c  om*/
    textView.setMaxWidth(500);
    textView.setMaxHeight(500);
    textView.setMaxLines(4);
    textView.setX(posX);
    textView.setY(posY);
    textView.setText(text);
    textView.setTextSize(size);

    LinearLayout layout = new LinearLayout(getContext());
    layout.addView(textView);
    layout.measure(500, 500);
    layout.layout(0, 0, 500, 500);

    textView.setDrawingCacheEnabled(true);
    textView.buildDrawingCache();
    Bitmap bm = textView.getDrawingCache();
    return bm;
}