程序中使用dimension中定义的尺寸大小不对的原因 (2013-02-26 09:18:26)转载▼
When you define a dimension in a resource file you include the measurement unit. If you use sp units they are scaled according to the screen density so text at 15sp should appear roughly the same size on screens of differing density. (The real screen density of the device isn't going to exactly match as Android generalises screen density into 120, 160, 240 and 320 dpi groups.)
When calling getResources().getDimension(R.dimen.textsize) it will return the size in pixels. If using sp it will scaled by the screen density,
Calling setText(float) sets the size in sp units. This is where the issue is ie you have pixels measurements on one hand and sp unit on the other to fix do this:
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.textsize));
Note you can also use
getResources().getDimensionPixelSize(R.dimen.textSize);
instead of getDimension() and it will round and convert to an non fractional value.
dimen 必须设置 px
<dimen name="listview_largetextsize">18px</dimen>
<dimen name="listview_smalltextsize">14px</dimen>
分享到:
相关推荐
Dimension
在新建的FORM上使用系统的Dimension display功能
We give a tutorial overview of several geometric methods for dimension reduction. We divide the methods into projective methods and methods that model the manifold on which the data lies. For ...
Two Dimension Signal and image processing MIT Textbook 麻省理工教材
UMESHMOTION子程序模拟接触磨损 1. 背景 UMESHMOTION 是应用于Abaqus/Standard 模块的一个子程序,与ALE 自适应网格技术 联合使用可以控制节点的运动。由于调整节点的过程并不会改变应力应变分布,所以该子程 序常...
Business Objects Merge Dimension
dimension-2400_owner's manual中文版,老电脑的资料
有时候需要将一批图片进行尺寸归一化操作。如在训练AdBoost的时候,需要更选取的相应特征模型将标记并裁减出来的正样本进行尺寸归一化成20x20、24x24、64x64。这里基于OpenCV提供了一个对指定文件夹下的图片进行尺寸...
English version, cover some InfoCube modeling best practices like M:N relationship of Master data, one or two dimensions, partitioning
PDAL-Dimension.cpp c++ pdal lidar library
本文实例讲述了Python的“二维”字典 (two-dimension dictionary)定义与实现方法。分享给大家供大家参考,具体如下: Python 中的dict可以实现迅速查找。那么有没有像数组有二维数组一样,有二维的字典呢?比如我...
Matlab 计算曲线的分型维数fractal dimension,FD
Data Quality: The Accuracy Dimension is about assessing the quality of corporate data and improving its accuracy using the data profiling method. Corporate data is increasingly important as companies ...
CSS 尺寸 (Dimension) CSS 尺寸 (Dimension) 属性允许你控制元素的高度和宽度。同样,它允许你增加行间距。 更多实例 这个例子演示了如何设置不同元素的高度。 这个例子演示了如何使用百分比值设置元素的高度。...
Rather, Imagining the Tenth Dimension is a mind-expanding exercise that could change the way you view this incredible universe in which we live. Read the book whose companion website (tenthdimension...
Ising model (2-dimension) fortran code
Constant Velocity (in One Dimension)恒定的速度(在一个尺寸).pptx
Three_dimensiona ThreadConnection,基于ANSYS分析得出的三维分析
Dimension Reduction A Guided Tour give a tutorial overview of several foundational methods for dimension reduction. We divide the methods into projective methods and methods that model the manifold on...
分形维度指数(Fractal Dimension Index)指标体现了市场动荡的程度.