android不同机型上界面适配问题
Android 不同 界面 适配 问题 机型
2023-09-11 14:14:10 时间
android中长度有:dp(或者dip device independent pixels)一种基于屏幕密度的抽象单位。在每英寸160点的显示器上。1dp=1px。
不同设备有不同的显示效果。这个和设备硬件有关。布局时尽量使用单位dp;sp(Scaled Pixels)主要用于字体显示,与刻度无关的一种像素,与dp类似。可是能够依据用户的字体大小首选项进行缩放。px:表示屏幕实际的象素。TextView 的方法setTextSize使用sp作为字号单位。Point的方法setTextSize使用px为单位。以下是转换放方法:
public static int px2sp(Context context, float pxValue) { final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; return (int) (pxValue / fontScale + 0.5f); } public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); }
相关文章
- Android Studio第一次启动的Fetching android sdk component information的问题
- Android 开源项目android-open-project解析之(二) GridView,ImageView,ProgressBar,TextView
- Android之 ImageView android:src和tools:src的区别是什么?
- LeetCode高频题:Android系统中WakeLock防止手机进入睡眠模式,统计出每个应用对WakeLock的不同贡献值
- Android-Unable to resolve target 'android-8'
- Android studio的错误:radle sync failed: Cause: failed to find target android-21 :
- 《Android游戏开发详解》一2.1 面向对象编程
- Android---- 获取当前应用的版本号和当前android系统的版本号
- Android 仿PhotoShop调色板应用(四) 不同区域颜色选择的颜色生成响应
- Android的Touch系统简介(一)
- android 点击下弹动画实现
- Android TextView 实现文字大小不同和文字颜色不同
- HashMap在Android和Java中的不同实现
- android实现界面左右滑动(GridView动态设置item,支持每个item按某个属性排序来显示在不同的界面)
- Android权限设置android.permission完整列表
- 在Android上使用ZXing识别条形码/二维码
- android开发:Android 中自定义View的应用
- Android图形显示系统——上层显示1:界面绘制大纲---android的GUI系统
- Android混合开发之Activity类与html页面之间的相互跳转(并解决黑屏问题)
- eclipse(adt-bundle)的Android SDK Manager下载不了谷歌的东西怎么办?
- 【Android】自带Theme
- Android的分屏模式开发注意事项
- android 性能优化 -- 启动过程 冷启动 热启动
- 【Android开发经验】怎样查看android-support-v4支持包中的源代码
- Android学习笔记之:android更新ui的几种经常用法
- Android Studio 工具之 Json 工具 Gson 的源码和各个版本 jar 下载地址整理
- android中依据不同分辨率dp和px的相互转算
- android_我的第一个Android程序