安卓开发之自动缩放布局

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

相关推荐
千里马学框架1 分钟前
google官方文档:深入剖析ProtoLog原理及Winscope的查看方式
android·车载系统·framework·perfetto·系统开发·winscope
apihz3 分钟前
获取当前北京时间的免费API接口教程
android
apihz5 分钟前
货币汇率换算免费API接口(每日更新汇率)
android·java·开发语言
恋猫de小郭26 分钟前
八年开源,GSY 用五种技术开发了同一个 Github 客户端,这次轮到 AI + Compose
android·前端·flutter
sc.溯琛9 小时前
MySQL 高级实战:触发器、事务与数据库备份恢复全攻略
android·adb
zhuzewennamoamtf9 小时前
Linux SPI设备驱动
android·linux·运维
雨声不在12 小时前
gradle编译missing_rules报错处理
android·gradle·agp8
用户70937225385114 小时前
配置vscode阅读Android native 代码
android
tangweiguo0305198714 小时前
Android OpenGL ES 2.0 完整开发指南:从零到三维旋转立方体
android
龚礼鹏15 小时前
AndroidStudio module编译aar混淆文件处理
android