[英]Scale textsizes for different screen sizes
I have some layouts and I want to adjust my textsize to the screen size. 我有一些布局,我想将文本大小调整为屏幕大小。 I used sp for all my sizes, but when I switch to my tablet my text still looks to small. 我使用sp表示所有尺寸,但是当我切换到平板电脑时,文字仍然很小。
Is there a common scale formula or something to simply do this ? 是否有一个通用的比例公式或简单地执行此操作的方法?
try View.getHeight()
and View.getWidth()
and apply your logic accordingly. 尝试使用View.getHeight()
和View.getWidth()
并相应地应用您的逻辑。
OR 要么
Use this : 用这个 :
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
OR 要么
To get screen size in inches, try : 要获取以英寸为单位的屏幕尺寸,请尝试:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
double x = Math.pow(dm.widthPixels/dm.xdpi,2);
double y = Math.pow(dm.heightPixels/dm.ydpi,2);
double screenInches = Math.sqrt(x+y);
Log.d("debug","Screen inches : " + screenInches);
使用dip
而不是sp
但我确定默认的textsize取决于其容器,例如textView或Button
you can use 您可以使用
android:textSize="dip"
for eg. 例如 10 dip,20 dip
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.