獲取文字高度:
1.基準線是baseline
2.ascent:字型在baseline上方被推薦的距離(一些字型製作商需要參考這個)
3.descent:字型在是baseline下方被推薦的距離(一些字型製作商需要參考這個)
4.top:ascent的最大值
5.bottom:descent的最大值
//四個值的原始碼:
public
static
class
fontmetrics
獲取文字寬度:
paint提供了下面4個過載方法,返回文字的寬度,型別是float
public
float
measuretext(string text)
public
float
measuretext(char text, int index, int count)
public
float
measuretext(string text, int start, int end)
public
float
measuretext(charsequence text, int start, int end)
或者使用paint.gettextbounds方法直接獲取寬高:
public
void
gettextbounds(string text, int start, int end, rect bounds)
string test = "qinshimingyue";
rect rect = new rect();
mpaint.gettextbounds(text, 0, test.length(), rect);
int width = rect.width();//文字寬
int height = rect.height();//文字高
四 View 的測量寬高和最終寬高的區別
這個問題可以具體為getmeasuredheight 和getheight 有什麼區別。view public final intgetheight 再看看 mbottom mtop 是怎麼來的 view protected boolean setframe int left,int top,int...
android 獲取螢幕寬高
發現專案中有兩種獲取螢幕寬高的方法 一 通過windowmanager獲取display,通過display獲取metrics,通過metrics獲取寬高。最後的單位是px。public static final int getscreenwidth 二 通過windowmanager獲取displ...
Android獲取螢幕寬高
方法一 windowmanager wm1 this.getwindowmanager int width1 wm1.getdefaultdisplay getwidth int height1 wm1.getdefaultdisplay getheight 方法二 windowmanager wm...