Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int totalLineCount = textView.getLineCount();
- int lineHeight = textView.getLineHeight();
- int totlaHeight = totalLineCount * lineHeight;
- float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
- int px = scaledDensity*sp;
- ViewTreeObserver viewTreeObserver = textView.getViewTreeObserver();
- viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- int width = textView.getWidth();
- int height= textView.getHeight()
- textView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
- }
- });
- Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
- paint.setStyle(Paint.Style.FILL);
- paint.setColor(color);
- paint.setTextAlign(Paint.Align.CENTER);
- paint.setTextSize(textSize); //размер шрифта в **пикселях**
- Rect bounds = new Rect();
- String text = "your text here";
- paint.getTextBounds(text , 0, text.length(), bounds);
- int height = bounds.height();//высота
- int width = bounds.width();//ширина
- textView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
- int height = textView.getMeasuredHeight();
- int width = textView.getMeasuredWidth();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement