前言
人們總是喜歡犯以爲是的錯誤,編程也不例外。於是讓我們看看曾經走過的坑吧
事例:
一、TextSize
易錯點:
我們總以爲:
View.setTextSize(int size1)
int size2=View.getTextSize()size1和size2單位一樣
實際上API裏是這樣滴:
setTextSize
/**
* Set the default text size to the given value, interpreted as “scaled
* pixel” units. This size is adjusted based on the current density and
* user font size preference.
*
* @param size The scaled pixel size.
*
* @attr ref android.R.styleable#TextView_textSize
*/
@android.view.RemotableViewMethod
public void setTextSize(float size) {
setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
}
getTextSize
/**
* @return the size (in pixels) of the default text size in this TextView.
*/
public float getTextSize() {
return mTextPaint.getTextSize();
}