安卓开发之自动缩放布局

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

相关推荐
恋猫de小郭5 分钟前
为什么跨平台框架可以适配鸿蒙,它们的技术原理是什么?
android·前端·flutter
张风捷特烈1 小时前
每日一题 Flutter#5,6 | 两道 Widget 选择题
android·flutter
移动开发者1号1 小时前
App主界面点击与跳转启动方式区别
android·kotlin
移动开发者1号1 小时前
我用Intent传大图片时竟然崩了,怎么回事啊
android·kotlin
androidwork13 小时前
Android LinearLayout、FrameLayout、RelativeLayout、ConstraintLayout大混战
android·java·kotlin·androidx
每次的天空13 小时前
Android第十三次面试总结基础
android·面试·职场和发展
wu_android13 小时前
Android 相对布局管理器(RelativeLayout)
android
李斯维15 小时前
循序渐进 Android Binder(二):传递自定义对象和 AIDL 回调
android·java·android studio
androidwork15 小时前
OkHttp 3.0源码解析:从设计理念到核心实现
android·java·okhttp·kotlin
像风一样自由16 小时前
【001】frida API分类 总览
android·frida