@@ -11,7 +11,7 @@ import android.widget.RelativeLayout
11
11
import android.widget.TextView
12
12
import com.pengxh.kt.lite.R
13
13
import com.pengxh.kt.lite.extensions.dp2px
14
- import com.pengxh.kt.lite.extensions.sp2px
14
+ import com.pengxh.kt.lite.extensions.getScreenDensity
15
15
16
16
17
17
/* *
@@ -47,7 +47,8 @@ class TitleBarView constructor(context: Context, attrs: AttributeSet) :
47
47
textView.text = title
48
48
textView.isSingleLine = true
49
49
textView.ellipsize = TextUtils .TruncateAt .END
50
- textView.textSize = titleSize.sp2px(context)
50
+ // textSize会将值默认为sp,不除以像素密度则会将sp再此转为px,相当于原本字体大小进行了两次转换px
51
+ textView.textSize = titleSize / context.getScreenDensity()
51
52
textView.gravity = Gravity .CENTER
52
53
textView.setTextColor(titleColor)
53
54
titleParams.addRule(CENTER_IN_PARENT , TRUE )
@@ -78,7 +79,8 @@ class TitleBarView constructor(context: Context, attrs: AttributeSet) :
78
79
textView.text = title
79
80
textView.isSingleLine = true
80
81
textView.ellipsize = TextUtils .TruncateAt .END
81
- textView.textSize = titleSize.sp2px(context)
82
+ // textSize会将值默认为sp,不除以像素密度则会将sp再此转为px,相当于原本字体大小进行了两次转换px
83
+ textView.textSize = titleSize / context.getScreenDensity()
82
84
textView.gravity = Gravity .CENTER
83
85
textView.setTextColor(titleColor)
84
86
titleParams.leftMargin = textMargin
0 commit comments