public class DisplayUtil { /** * 将px值转换为dip或dp值,保证尺寸大小不变 * * @param pxValue scale * (DisplayMetrics类中属性density) * @return */ public static int px2dip(float pxValue) { final float scale = x.app().getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } /** * 将dip或dp值转换为px值,保证尺寸大小不变 * * @param dipValue scale * (DisplayMetrics类中属性density) * @return */ public static int dip2px(float dipValue) { final float scale = x.app().getResources().getDisplayMetrics().density; return (int) (dipValue * scale + 0.5f); } /** * 将px值转换为sp值,保证文字大小不变 * * @param pxValue fontScale * (DisplayMetrics类中属性scaledDensity) * @return */ public static int px2sp(float pxValue) { final float fontScale = x.app().getResources().getDisplayMetrics().scaledDensity; return (int) (pxValue / fontScale + 0.5f); } /** * 将sp值转换为px值,保证文字大小不变 * * @param spValue fontScale * (DisplayMetrics类中属性scaledDensity) * @return */ public static int sp2px(float spValue) { final float fontScale = x.app().getResources().getDisplayMetrics().scaledDensity; return (int) (spValue * fontScale + 0.5f); } // //手机屏幕尺寸 // public static String getScreenSizeOfDevice(Activity context) { int w=context.getWindowManager().getDefaultDisplay().getWidth(); int h=context.getWindowManager().getDefaultDisplay().getHeight(); float ydpi=x.app().getResources().getDisplayMetrics().ydpi; float xdpi= x.app().getResources().getDisplayMetrics().xdpi; float hInches=h/ydpi; float wInches=w/xdpi; double screenInches =Math.sqrt(Math.pow(hInches, 2) + Math.pow(wInches, 2)); return (screenInches + ""); } /** * ListView已到顶部的判断 * @param listView * @return */ public static boolean isListViewReachTopEdge(final ListView listView) { boolean result=false; if(listView.getFirstVisiblePosition()==0){ final View topChildView = listView.getChildAt(0); result=topChildView.getTop()==0; } return result ; } /** * ListView已到底部的判断 * @param listView * @return */ public static boolean isListViewReachBottomEdge(final ListView listView) { boolean result=false; if (listView.getLastVisiblePosition() == (listView.getCount() - 1)) { final View bottomChildView = listView.getChildAt(listView.getLastVisiblePosition() - listView.getFirstVisiblePosition()); result= (listView.getHeight()>=bottomChildView.getBottom()); }; return result; } }
关于显示的Util
转载上一篇:Android大神博客收集
下一篇:利用发射进行对象赋值
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
关于spring中<util:**/>的配置
合,然而这些集合不...
java spring xml -
关于无线显示器的连接
无线设备,电视作为无线显示器
Windows