谷歌官方支持按照百分比来设置布局的宽高。

支持PercentRelativeLayout和PercentFrameLayout,分别继承自RelativeLayout和FrameLayout

均支持以下属性:

  • layout_widthPercent
  • layout_heightPercent
  • layout_marginPercent
  • layout_marginLeftPercent
  • layout_marginTopPercent
  • layout_marginRightPercent
  • layout_marginBottomPercent
  • layout_marginStartPercent
  • layout_marginEndPercent

效果图:

如何使用:

添加支持库到你的工程(Studio)

dependencies {compile 'com.android.support:percent:22.2.0'
}

布局文件

PercentRelativeLayout

<android.support.percent.PercentRelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"><Viewandroid:id="@+id/top_left"android:layout_width="0dp"android:layout_height="0dp"android:layout_alignParentTop="true"android:background="#ff44aacc"app:layout_heightPercent="20%"app:layout_widthPercent="70%" /><Viewandroid:id="@+id/top_right"android:layout_width="0dp"android:layout_height="0dp"android:layout_alignParentTop="true"android:layout_toRightOf="@+id/top_left"android:background="#ffe40000"app:layout_heightPercent="20%"app:layout_widthPercent="30%" /><Viewandroid:id="@+id/bottom"android:layout_width="match_parent"android:layout_height="0dp"android:layout_below="@+id/top_left"android:background="#ff00ff22"app:layout_heightPercent="80%" />
</android.support.percent.PercentRelativeLayout>


非常简单易用!

GitHub示例:

https://github.com/JulienGenoud/android-percent-support-lib-sample

官方开发文档:

https://juliengenoud.github.io/android-percent-support-lib-sample/

Android Percent Layout 安卓百分比布局相关推荐

  1. Android屏幕适配之百分比布局LinearLayout、RelativeLayout、FrameLayout

    谷歌的百分比库已废弃,转用约束布局,本博文仅供参考思路.新方法请参考:https://blog.csdn.net/qq_21480607/article/details/98790567 一.首先说一 ...

  2. android 分区layout以及虚拟内存布局-小结

    摘要 简述启动过程的内存分配,各个映像的烧写,加载,logo的刷新,文件系统mount. DRAM:外部RAM: ISRAM:内部RAM(128K),(PL会跑在ISRAM里面,去初始化DRAM,lo ...

  3. android设置高度比例,android开发layout按比例布局(详解)

    释放双眼,带上耳机,听听看~! 由于Android的复杂性,在写程序的时候经常会遇见一些难题,也可能会遇见处理不了的问题,下面是技术狗小编详解android layout 按比例布局的代码,一起进入下 ...

  4. android百分比布局失效,Android Studio不能添加百分比布局的依赖,书和AS不一样,老报错,怎么弄?急~~~...

    我正好也在看这本书,这里也遇到同样的问题,不过仔细对比书上,可以看到书上的定义有: compile 'com.android.support:appcompat-v7:24.2.1' compile  ...

  5. Android百分比布局支持和垂直TextView

    In this tutorial, we'll discuss and implement Android Percent Layout Support Library. Furthermore, w ...

  6. Android系统布局——android.R.layout详解

    布局文件,作为android中必不可少的一部分,android系统为了方便开发人员,在系统中定义了很多的布局文件. 系统布局文件和我们自定义的布局在写法用前缀android以示区别: 系统布局文件:a ...

  7. android百分比布局适配,安卓屏幕适配-百分比布局

    屏幕适配-百分比布局 原理:以父容器尺寸作为参考,在View的加载过程,根据当前父容器实际尺寸换算出目标尺寸,在作用在View上. 百分比布局实际是对容器的一中扩展,扩展的是宽高等比例的设置. 1.自 ...

  8. android百分比扩展枯,Android 增强版百分比布局库 为了适配而扩展

    一 概述 上周一我们发布了Android 百分比布局库(percent-support-lib) 解析与扩展中对percent-support这个库进行了解析和添加了PercentLinearLayo ...

  9. Android 百分比布局、权重、隐藏TitleBar、引入自定义控件

    一.LinearLayout权重 1.1.android:layout_weight="1" 两个控件设置为1可以将屏幕等分为两份,更改数值可以根据各自数值各占有屏幕的尺寸    ...

最新文章

  1. Doctype作用? 严格模式与混杂模式如何区分?它们有何意义
  2. PhotoShop算法原理解析系列 - 像素化---》碎片。
  3. 模型-视图-提供器 模式
  4. 五、Go语言复合数据类型(下)
  5. 关于四金计算和工资对照表
  6. NuGet Error:Unable to find version ‘0.3.3.0‘ of package ‘glog.overlay-x64_v120_Release_dynamic‘.
  7. 体育赛事中的概率计算问题
  8. python的去重函数_python去重函数是什么
  9. AJAX JSONP源码实现(原理解析)
  10. 一起学Windows Phone7开发(十四.一 Phone Task)
  11. 导出无法正常启动的VMware虚拟机中的文件
  12. 如何实现一个遵从设计原则的积分兑换系统2
  13. Windows 添加用户
  14. Python 代码格式化工具 「Black」 使用详解(摘录翻译自官方文档)
  15. windows 打包c++运行库
  16. (1.4.10)SXF笔试题汇总
  17. 如何用用计算机名访问共享打印机,局域网怎么连接共享打印机共享
  18. 【技术知识】SVAC 2.0安全技术浅析
  19. mysql on是什么意思_这SQL语句里的ON 是什么意思啊
  20. dex2jar源码解析----解析dex文件一

热门文章

  1. 云服务器与虚拟主机有什么区别,我们应该如何选择?
  2. 88steam@88skins CSGO饰品皮肤开箱DOTA2饰品开箱即开即取网站
  3. 元宇宙是什么,如何看待未来元宇宙的发展?
  4. 绿联扩展坞拆解_绿联最新豪华版3A1C四口多功能扩展坞深度拆解,用料满满
  5. 独家 | OpenAI的DALL·E模型使人类更接近通用人工智能(附链接)
  6. vue精通之路:掌握这42个Vue知识点,你将成为大shen
  7. 计算机组装与操作系统安装实验报告,操作系统安装实验报告(共10篇).docx
  8. C++ RegSetValueEx返回值始终为5
  9. 化学绘图软件ChemDraw真的什么都能干!
  10. oracle hana 字段长度,学习SAP HANA 数据类型(SAP HANA DATA TYPES)--像学Oracle一样学习SAP HANA...