Android屏幕适配之使用布局别名

我们在平时的Android开发中总是会遇到屏幕适配的问题,接下来我会介绍下出现的问题以及为什么要使用布局别名。
摘要由CSDN通过智能技术生成

转载请注明出处:http://blog.csdn.net/footballclub/

前言

我们在平时的Android开发中总是会遇到屏幕适配的问题,接下来我会介绍下出现的问题以及为什么要使用布局别名。

基本概念和知识点

分辨率:整个屏幕的像素点的个数,常见的有1280*720,1920*1080

屏幕密度:表示单位面积内的像素个数,通常用dpi为单位,即每英寸多少个像素点

px:像素单位,屏幕上像素点的大小不是固定的,像素点可大可小

dp:长度单位,与具体屏幕密度无关,显示的时候根据具体平台屏幕密度的不同最终转换为相应的像素长度,具体转换规则是: 1px = (目标屏幕密度/标准密度)*dp,标准密度为160dpi,例如,1dp长度在密度为160dpi的平台表示一个像素的长度,而在240dpi的平台则表示1.5个像素的长度

屏幕尺寸:屏幕的大小,通常用屏幕对角线的长度表示,屏幕的大小和屏幕的分辨率没有必然关系,也就是说大屏幕的手机的分辨率不一定比小屏幕手机的分辨率大。

问题背景

下表介绍了屏幕密度和分辨率的关系对照表

<
名称 屏幕密度 通常分辨率
mhdpi ~160dpi 320*480
hdpi ~240dpi 480*800
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是 Android 使用极光推送绑定别名的代码示例: ```java import cn.jpush.android.api.JPushInterface; // 绑定别名 JPushInterface.setAlias(context, sequence, alias); // 解绑别名 JPushInterface.deleteAlias(context, sequence); ``` 其中,`context` 参数为当前上下文对象,`sequence` 参数为请求码,`alias` 参数为需要绑定的别名。 注意事项: - 绑定别名时,如果已经绑定了别名,则会覆盖之前的别名; - 解绑别名时,如果当前设备没有绑定别名,则不会有任何影响。 另外,在使用极光推送时,需要在 AndroidManifest.xml 文件中添加以下权限: ```xml <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="cn.jpush.android.permission.RECEIVE_MSG" /> <uses-permission android:name="cn.jpush.android.permission.READ_PHONE_STATE" /> <uses-permission android:name="cn.jpush.android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="cn.jpush.android.permission.VIBRATE" /> <uses-permission android:name="cn.jpush.android.permission.RECEIVE_BOOT_COMPLETED" /> ``` 并且,需要在 AndroidManifest.xml 文件中添加以下服务和接收器: ```xml <!-- 极光推送服务 --> <service android:name="cn.jpush.android.service.PushService" android:enabled="true" android:exported="false" > <intent-filter> <action android:name="cn.jpush.android.intent.REGISTER" /> <action android:name="cn.jpush.android.intent.REPORT" /> <action android:name="cn.jpush.android.intent.PushService" /> <action android:name="cn.jpush.android.intent.PUSH_TIME" /> </intent-filter> </service> <!-- 极光推送接收器 --> <receiver android:name="cn.jpush.android.service.PushReceiver" android:enabled="true" > <intent-filter android:priority="1000"> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.REGISTRATION" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.UNREGISTRATION" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <category android:name="${applicationId}" /> <data android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.USER_PRESENT" /> <category android:name="${applicationId}" /> </intent-filter> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> <!-- 极光推送唤醒接收器 --> <receiver android:name="cn.jpush.android.service.AlarmReceiver" android:enabled="true" /> ``` 以上是 Android 使用极光推送绑定别名的代码示例及注意事项。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值