用于返回屏幕大小相关信息,方便你根据此来设计控件尺寸
快速开始
点击ScreenSizeUtils查看源码,欢迎Star,fork,并在issue提出改进意见
implementation 'io.github.sakurajimamaii:VastTools:0.0.3'
概括
私有属性
| Param Name | Param Class |
|---|---|
| sRealSizes | Array<Point?> |
| DefaultDevice | AspectRatioDevice 默认Device,将屏幕长宽比大于1.97的设备定义为全面屏 |
| defaultAspectRatioList | MutableList 默认设备屏幕长宽比信息类列表 |
| AspectRatioDeviceList | MutableList 设备屏幕长宽比信息类列表 |
私有方法
| Returns | Method |
|---|---|
| Int | fun getScreenHeight(context: Context) |
| Int | fun getScreenRealHeightApi30Above(context: Context) Api 30 以上推荐使用 |
| Int | fun getScreenRealHeightApi30Down(context: Context) Api 30 以下推荐使用 |
公有方法
| Returns | Method |
|---|---|
| Boolean | fun isAllScreenDeviceApi31(context: Context,deviceTag: String = DefaultDevice.tag) Api 31 推荐使用 |
| Boolean | fun isAllScreenDeviceApi30(context: Context,deviceTag: String = DefaultDevice.tag) Api 30 推荐使用 |
| Boolean | fun isAllScreenDeviceApi30Down(context: Context,deviceTag: String = DefaultDevice.tag) Api 30 以下推荐使用 |
| Int | fun getMobileScreenWidth(context: Context) |
| Int | fun getMobileScreenHeightApi31(context: Context) Api 31 推荐使用 |
| Int | fun getMobileScreenHeightApi30(context: Context) Api 30 推荐使用 |
| Int | fun getMobileScreenHeightApi30Down(context: Context) Api 30 以下推荐使用 |
| Unit | fun addDevice(vararg devices: AspectRatioDevice) 添加设备屏幕的长宽比信息。 |
| Unit | fun removeDevice(device: AspectRatioDevice) 删除设备屏幕的长宽比信息。 |
| Unit | fun resetDeviceList() 重置AspectRatioDeviceList |
公有方法
全面屏判断
// Use in api 31
fun isAllScreenDeviceApi31(context: Context,deviceTag: String = DefaultDevice.tag): Boolean
// Use in api 30
fun isAllScreenDeviceApi30(context: Context,deviceTag: String = DefaultDevice.tag): Boolean
// Use in api 30 down
fun isAllScreenDeviceApi30Down(context: Context,deviceTag: String = DefaultDevice.tag): Boolean
判断你的设备是否是全面屏
参数
context:Context 函数所在的上下文
deviceTag:String 你设备的 tag 借此判断你设备全面屏应该符合的屏幕长宽比
返回值
Boolean 如果是全面屏返回 true ,否则返回 false
getMobileScreenWidth
fun getMobileScreenWidth(context: Context):Int
返回设备的屏幕宽度
参数
context:Context 函数所在的上下文
返回值
Int 返回屏幕的宽度,单位是 pixels ,返回 0 代表获取失败
屏幕高度获取
// Use in api 31
fun getMobileScreenHeightApi31(context: Context):Int
// Use in api 30
fun getMobileScreenHeightApi30(context: Context):Int
// Use in api 30 down
fun getMobileScreenHeightApi30Down(context: Context):Int
返回设备的屏幕高度
参数
context:Context
函数所在的上下文
返回值
Int 返回屏幕的高度,单位是 pixels ,返回 0 代表获取失败