本文实例讲述了android获取手机屏幕宽高、状态栏高度以及字符串宽高信息的方法。分享给大家供大家参考。具体如下:
首先定义textview对象commenttext
获取文字的宽高:
textpaint textpaint = new textpaint(paint.anti_alias_flag); textpaint.settextsize(commenttext.gettextsize()); textpaint.setcolor(color.white); fontmetrics fontmetrics = textpaint.getfontmetrics(); float ftop = fontmetrics.top; float fbottom = fontmetrics.bottom; float textheight = (int)(fbottom - ftop); float textwidth = (int)textpaint.measuretext(commenttext.gettext());
获取手机屏幕上方状态栏高度:
获取手机屏幕宽高:
获取textview宽度
textpaint paint = textview.getpaint(); float len = paint.measuretext(string);
获取屏幕尺寸:
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); //屏幕尺寸(英寸)
希望本文所述对大家的android程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
Android SDK Manager 不知为什么突然打不开了?看这里
监听Android系统发出的插入SD卡并且已正确安装(识别)时发出的广播
RecyclerView三种常用效果的实现方法-android-kotlin
Android Studio app启动错误 Error running :Default Activity not found
网友评论