安卓开发之自动缩放布局

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

相关推荐
zhangphil25 分钟前
Android Coli 3 ImageView load two suit Bitmap thumb and formal,Kotlin(七)
android·kotlin
与籍同行2 小时前
开发过程中遇到Selinux问题分析
android·selinux
韩仔搭建3 小时前
安卓端互动娱乐房卡系统调试实录:从UI到协议的万字深拆(第一章)
android·ui·娱乐
limingade3 小时前
手机打电话时如何将通话对方的声音在手机上识别成文字
android·智能手机·语音识别·funasr·蓝牙电话·ai电话机器人·funasr安卓移植和部署
努力学习的小廉4 小时前
深入了解linux系统—— 基础IO(上)
android·linux·运维
tmacfrank4 小时前
Android 性能优化入门(一)—— 数据结构优化
android·数据结构·性能优化
东风西巷4 小时前
Screen Mirroring App:轻松实现手机与电视的无缝投屏
android·智能手机·生活·软件需求
每次的天空5 小时前
Android第三次面试总结之网络篇补充
android·网络·面试
uwvwko17 小时前
BUUCTF——web刷题第一页题解
android·前端·数据库·php·web·ctf
fzxwl17 小时前
隆重推荐(Android 和 iOS)UI 自动化工具—Maestro
android·ui·ios