List of usage examples for android.widget TextView measure
public final void measure(int widthMeasureSpec, int heightMeasureSpec)
This is called to find out how big a view should be.
From source file:com.skytree.epubtest.BookViewActivity.java
int getLabelWidth(TextView tv) { tv.measure(0, 0); //must call measure! return tv.getMeasuredWidth(); //get height }
From source file:com.skytree.epubtest.BookViewActivity.java
int getLabelHeight(TextView tv) { tv.measure(0, 0); //must call measure! return tv.getMeasuredHeight(); //get width }
From source file:com.juick.android.MessagesFragment.java
public void lastPrepareMessages(final List<JuickMessage> list, final Runnable then) { databaseGetter.getService(new Utils.ServiceGetter.Receiver<DatabaseService>() { @Override/*from ww w .ja va2s . c o m*/ public void withService(final DatabaseService service) { new Thread("processLastReads cont") { @Override public void run() { for (JuickMessage juickMessage : list) { // we can use service inside here, because getMessageReadStatus0 is thread-safe final DatabaseService.MessageReadStatus messageReadStatus0 = service .getMessageReadStatus0(juickMessage.getMID()); if (messageReadStatus0.read) { juickMessage.read = true; juickMessage.readComments = messageReadStatus0.nreplies; } } final Activity act = getActivity(); if (act != null) { if (sp.getBoolean("text_accelerated", false)) { // accelerate text draw final Bitmap bm = Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8); while (MessagesFragment.this.getView().getMeasuredWidth() == 0) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } TextView tv = new TextView(act); tv.setTextSize(JuickMessagesAdapter.getTextSize(act)); MainActivity.restyleChildrenOrWidget(tv); final int outerViewWidth = MessagesFragment.this.getView().getMeasuredWidth(); final int width = outerViewWidth - 6; tv.setWidth(width); tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); final ArrayList<JuickMessagesAdapter.CanvasPainter> stuff = new ArrayList<JuickMessagesAdapter.CanvasPainter>(); Canvas canvas = new Canvas(bm) { @Override public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { super.drawText(text, index, count, x, y, paint); //To change body of overridden methods use File | Settings | File Templates. } @Override public void drawText(String text, float x, float y, Paint paint) { super.drawText(text, x, y, paint); //To change body of overridden methods use File | Settings | File Templates. } @Override public void drawText(String text, int start, int end, float x, float y, Paint paint) { super.drawText(text, start, end, x, y, paint); //To change body of overridden methods use File | Settings | File Templates. } @Override public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { super.drawText(text, start, end, x, y, paint); //To change body of overridden methods use File | Settings | File Templates. } @Override public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset, float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, int indexOffset, int indexCount, Paint paint) { super.drawVertices(mode, vertexCount, verts, vertOffset, texs, texOffset, colors, colorOffset, indices, indexOffset, indexCount, paint); //To change body of overridden methods use File | Settings | File Templates. } @Override public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { super.drawPosText(text, index, count, pos, paint); //To change body of overridden methods use File | Settings | File Templates. } @Override public void drawPosText(String text, float[] pos, Paint paint) { super.drawPosText(text, pos, paint); //To change body of overridden methods use File | Settings | File Templates. } @Override public void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint paint) { super.drawTextOnPath(text, index, count, path, hOffset, vOffset, paint); //To change body of overridden methods use File | Settings | File Templates. } @Override public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { super.drawTextOnPath(text, path, hOffset, vOffset, paint); //To change body of overridden methods use File | Settings | File Templates. } public void drawTextRun(final CharSequence text, final int start, final int end, final int contextStart, final int contextEnd, final float x, final float y, final int dir, final Paint paint) { stuff.add(new JuickMessagesAdapter.CanvasPainter() { Paint paintClone = getPaintFromCache(paint); @Override public void paintOnCanvas(Canvas c, Paint workPaint) { try { drawTextRun.invoke(c, text, start, end, contextStart, contextEnd, x, y, dir, paintClone); } catch (Throwable t) { } } }); } @Override public boolean getClipBounds(Rect bounds) { bounds.top = 0; bounds.bottom = 100000; bounds.left = 0; bounds.right = width; return true; } }; for (JuickMessage juickMessage : list) { JuickMessagesAdapter.ParsedMessage pm = (JuickMessagesAdapter.ParsedMessage) juickMessage.parsedText; if (pm != null && pm.textContent != null) tv.setText(pm.textContent); stuff.clear(); tv.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); tv.draw(canvas); if (stuff.size() > 0) { juickMessage.parsedUI = new JuickMessagesAdapter.RenderedText( outerViewWidth, tv.getMeasuredHeight(), new ArrayList<JuickMessagesAdapter.CanvasPainter>(stuff)); } else { juickMessage.parsedUI = null; } } } act.runOnUiThread(then); } } }.start(); } }); }