在axml文件中添加视图时,可以简单地指定视图属性的大小和单位,例如:
<TextVIEw androID:TextSize = "10sp" androID:layout_margintop = "10dp" />
但是,通过编程方式应用尺寸时,尺寸sp的单位是什么? dp? px?
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中应用尺寸单位?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)