安卓开发之自动缩放布局

AutoScalingLayout

适用于 Android 的自动缩放布局。

替换布局:

我们只需要替换根布局所需的自动缩放,子布局也将实现自动缩放。

原始布局 AutoScalingLayout
相对布局 ASRelativeLayout
线性布局 ASLinearLayout
FrameLayout(框架布局) ASFrameLayout

目前支持上述三种布局。

添加属性:

designWidth 和 designHeight 是在 xml 编辑器中设计 GUI 时使用的屏幕大小。例如,我使用 平板的xml,因此转换为 dp 的通用屏幕尺寸为 1280dp 和 720dp(不包括状态栏和操作栏)。

autoScaleEnable 用于启用/禁用缩放。

autoScaleType 可以是"fitInside"、"fitWidth"和"fitHeight"

XML 复制代码
<me.dreamheart.autoscalinglayout.ASLinearLayout         
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    custom:designWidth="1280dp"
    custom:designHeight="720dp"
    custom:autoScaleEnable="true"
    custom:autoScaleType="fitInside"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_bg"
    android:orientation="vertical"
    tools:context=".MainActivity">
  1. designWidth 和 designHeight 非常重要。如果分配了错误的值,则不会看到预期的布局。
  2. xml GUI 编辑器中使用的单位应保持不变。例如,如果将 dp 用于 designWidth 和 designHeight,则子视图的所有单位都必须是 dp,甚至字体大小也不能是 sp,因此为 px、pt。如果您只想复制 GUI 给出的像素值,只需对所有组件使用 px 即可。
  3. 应用 AutoScalingLayout 时,屏幕将保持 designWidth 和 designHeight 的纵横比,因此不必担心将方形布局意外转换为矩形。

参考如下:

项目概览 - AutoScalingLayout - GitCode

相关推荐
云霄IT6 分钟前
绕过Frida检测反调试的一些办法
android·javascript
sang_xb34 分钟前
Android 如何开启 16KB 模式
android·kotlin
alengan38 分钟前
安卓上谷歌35版本
android
珹洺2 小时前
Java-Spring入门指南(二十五)Android 的历史,认识移动应用和Android 基础知识
android·java·spring
大白的编程日记.2 小时前
【MySQL】数据库表的CURD(二)
android·数据库·mysql
介一安全3 小时前
【Frida Android】基础篇4:Java层Hook基础——调用静态方法
android·网络安全·逆向·安全性测试·frida
怪兽20143 小时前
主线程 MainLooper 和一般 Looper 的异同?
android·面试
洋不写bug4 小时前
数据库的创建,查看,修改,删除,字符集编码和校验操作
android·数据库·adb
2501_915909064 小时前
iOS App 上架全流程详解:证书配置、打包上传、审核技巧与跨平台上架工具 开心上架 实践
android·ios·小程序·https·uni-app·iphone·webview
2501_915106324 小时前
iOS 26 系统流畅度测试实战分享,多工具组合辅助策略
android·macos·ios·小程序·uni-app·cocoa·iphone