Android 測量字符串在屏幕中的寬度以及兩個空格的表示
1.兩個空格
<string name="spaceTwo"> </string>
2.獲取字符串在屏幕中的寬度
TextView content = findViewById(R.id.text_view);
Rect rect = new Rect();
String info = "Measure Text";
content.getPaint().getTextBounds(info,0,info.length(),rect);
//字符串在屏幕中的長度
int width = rect.width()
3.封裝
/**
* 測量字符串在屏幕中的寬高 rect.width() rect.height()
* @param content
* @param info
* @return
*/
public static Rect measureStringWidthOnScrren(TextView content,String info){
Rect rect = new Rect();
content.getPaint().getTextBounds(info,0,info.length(),rect);
return rect;
}