Android万能分辨率适应法
来源:互联网 发布:马拉车算法 编辑:程序博客网 时间:2024/05/29 04:23
(1)获取屏幕的尺寸
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);Display d = windowManager.getDefaultDisplay();mWidth = d.getWidth();mHeight = d.getHeight();DisplayMetrics dm = getResources().getDisplayMetrics();mScreenDensity = dm.density;
(2)美工设计图的尺寸
uiWidth,uiHeight
(3)获取缩放比例
float scaleWidth = mWidth / uiWidth;float scaleHeight = mHeight/ uiHeight;
(4)所有布局的尺寸用代码实现
public static int getWidthSize(int size){ return (int) (size * scaleWidth);}public static int getHightSize(int size){ return (int) (size * scaleHeight);}public static float getTextSize(int pxSize){ return (pxSize*scaleHeight) / mScreenDensity;}public static void setViewSize(int width, int height, View v){ int paramWidth = getWidthSize(width); int paramHeight = getHightSize(height); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); if (width != INVALID){ params.width = paramWidth; } if (height != INVALID){ params.height = paramHeight; } v.setLayoutParams(params);}public static void setViewPadding(int left, int top, int right, int bottom, View v){ left = getWidthSize(left); top = getHightSize(top); right = getWidthSize(right); bottom = getWidthSize(bottom); v.setPadding(left, top, right, bottom);}public static void setViewMargin(int left, int top, int right, int bottom, View v){ int paramLeft = getWidthSize(left); int paramTop = getHightSize(top); int paramRight = getWidthSize(right); int paramBottom = getHightSize(bottom); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); if (left != INVALID){ params.leftMargin = paramLeft; } if (right != INVALID){ params.rightMargin = paramRight; } if (top != INVALID){ params.topMargin = paramTop; } if (bottom != INVALID){ params.bottomMargin = paramBottom; } v.setLayoutParams(params);}
0 0
- Android万能分辨率适应法
- Android万能分辨率适应法
- Android万能分辨率适应法
- Android大分辨率适应
- android 多分辨率适应
- android 布局适应不同分辨率
- android程序适应各种分辨率
- android 不同分辨率,屏幕适应
- android程序适应各种分辨率
- Android程序适应多种分辨率
- (转)android 按比例布局 适应不同分辨率
- Android--让app适应不同分辨率
- 如何让android app适应不同分辨率
- Android 之百分比布局 适应不同分辨率
- Android zxing二维码扫描适应各种分辨率
- 怎样开发适应不同分辨率的Android应用
- android .9.png 点九PNG技术 适应不同分辨率
- 适应不同分辨率屏幕的问题 android layout
- DQM Serial Sync Index Program (DQM Serial Sync Index Program)
- cocos2d-x 3.0 WIN7+VS2012 安卓平台搭建
- java socket通信总结笔记3——SocketChannel和ServerSocketChannel
- PHP生成二维码二种方法分享
- java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.SimpleTriggerBea
- Android万能分辨率适应法
- poj1458_Common Subsequence
- 不吃青春饭,关于程序员将来的发展方向
- H264 获取SPS与PPS(附源码)
- 6.4 Insertion Sort List
- 菜单资源
- guava&&java
- codeforces Div.2 B.Suffix Structures
- 提问