在axml文件中添加 View 时,可以简单地指定 View 属性的大小和单位,例如:
<TextView
android:TextSize = "10sp"
android:layout_marginTop = "10dp" />
但是当以编程方式应用尺寸时,尺寸 sp 应用的单位是什么? DP?像素?
TextView tv = new TextView();
tv.TextSize = 10;
另外,如何转换单位?
最佳答案
sp
是 TextView.TextSize
的默认值:
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.`
如果您需要不同的单位类型 (ComplexUnitType
),请使用 SetTextSize
方法:
textview.SetTextSize(ComplexUnitType.Px, 20);
关于android - Android 中的大小单位是如何应用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54638131/