Percent Library百分比布局详解
PercentLibrary是Google在15年推出的一个支持百分比布局的类库,支持的相对布局和帧布局,不过网上有的人已经扩展出支持线性布局。这个类库的使用是非常的简单的,我们需要了解的只有两个类:android.support.percent.PercentRelativeLayout和android.support.percent.PercentFrameLayout分别对于上面的两个布局。
两个布局都是继承自对应的基本布局,都拥有下面的属性:
layout_heightPercen
layout_marginPercent
layout_marginLeftPercent
layout_marginTopPercent
layout_marginRightPercent
layout_marginBottomPercent
layout_marginStartPercent
layout_marginEndPercent
layout_aspectRatio
其实很简单,大致就3类:宽高、margin、宽高比。
使用步骤:
1、在gradle中引入类库:compile 'com.android.support:percent:25.3.1'
2、将对应的相对布局和帧布局替换成对应的百分比布局
3、将百分比布局下的子布局的宽高设为0,使用上面的属性设置其宽高。
因为非常的简单,这里我直接贴出一个效果图然后贴出布局代码,java中不需要编写任何的代码。
效果图:
对应的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns: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"android:background="#229961"><ScrollViewandroid:id="@+id/left_line"android:layout_width="0dp"android:layout_height="match_parent"app:layout_widthPercent="49%"><android.support.percent.PercentRelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:id="@+id/imgv1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:scaleType="fitXY"android:src="@drawable/first"app:layout_heightPercent="30%"app:layout_marginBottomPercent="1%" /><ImageViewandroid:id="@+id/imgv2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/imgv1"android:scaleType="fitXY"android:src="@drawable/secend"app:layout_heightPercent="30%" /><ImageViewandroid:id="@+id/imgv3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/imgv2"android:scaleType="fitXY"app:layout_marginTopPercent="1%"android:src="@drawable/third"app:layout_heightPercent="30%" /><ImageViewandroid:id="@+id/imgv4"android:layout_width="wrap_content"android:layout_height="0dp"android:layout_below="@+id/imgv3"android:scaleType="fitXY"android:src="@drawable/four" app:layout_marginTopPercent="1%"app:layout_heightPercent="30%" /><ImageViewandroid:id="@+id/imgv5"android:layout_width="wrap_content"android:layout_height="0dp"android:layout_below="@+id/imgv4"android:scaleType="fitXY"android:src="@drawable/five"android:background="#ccc"app:layout_marginTopPercent="1%"app:layout_heightPercent="30%" /></android.support.percent.PercentRelativeLayout></ScrollView><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_toLeftOf="@+id/right_line"android:layout_toRightOf="@id/left_line"android:background="@drawable/background_gradient"></LinearLayout><ScrollViewandroid:id="@+id/right_line"android:layout_width="0dp"android:layout_height="match_parent"android:layout_alignParentRight="true"app:layout_widthPercent="49%"><android.support.percent.PercentRelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:id="@+id/imgv6"android:layout_width="0dp"android:layout_height="0dp"android:scaleType="fitXY"android:src="@drawable/six"app:layout_aspectRatio="70%"app:layout_widthPercent="100%" /><ImageViewandroid:id="@+id/imgv7"android:layout_width="0dp"android:layout_height="0dp"android:layout_below="@+id/imgv6"android:scaleType="fitXY"android:src="@drawable/seven"app:layout_aspectRatio="70%"app:layout_widthPercent="100%" /><ImageViewandroid:id="@+id/imgv8"android:layout_width="0dp"android:layout_height="0dp"android:layout_below="@+id/imgv7"android:layout_centerHorizontal="true"android:scaleType="fitXY"android:src="@drawable/eight"app:layout_aspectRatio="70%"app:layout_widthPercent="70%" /><ImageViewandroid:id="@+id/imgv9"android:layout_width="0dp"android:layout_height="0dp"android:layout_below="@+id/imgv8"android:scaleType="fitXY"android:src="@drawable/nine"app:layout_heightPercent="50%"app:layout_widthPercent="100%" /><ImageViewandroid:id="@+id/imgv10"android:layout_width="match_parent"android:layout_height="300dp"android:layout_below="@+id/imgv9"android:scaleType="fitXY"android:src="@drawable/ten" /></android.support.percent.PercentRelativeLayout></ScrollView>
</android.support.percent.PercentRelativeLayout>
最近去官网查看发现,现在google推荐使用ConstraintLayout来代替该类库。尽管如此,我们还是有必要知道有这个类库的,而以后我会给ConstraintLayout的使用详细的介绍给大家。最后贴上demo吧:点击打开链接
欢迎关注我的微信公众号“android教科书”,最新最好的文章第一时间送到手!可以扫描下面的二维码来关注:
Percent Library百分比布局详解相关推荐
- 【C++】C++对象模型:对象内存布局详解(C#实例)
C++对象模型:对象内存布局详解 0.前言 C++对象的内存布局.虚表指针.虚基类指针解的探讨,参考. 1.何为C++对象模型? 引用<深度探索C++对象模型>这本书中的话: 有两个概念可 ...
- Linux进程地址空间与进程内存布局详解,内核空间与用户空间
Linux进程地址空间与进程内存布局详解 程序段(Text):程序代码在内存中的映射,存放函数体的二进制代码. 初始化过的数据(Data):在程序运行初已经对变量进行初始化的数据. 未初始化过的数据( ...
- DevExpress控件GridControl中的布局详解 【转】
DevExpress控件GridControl中的布局详解 [转] 2012-10-24 13:27:28| 分类: devexpress | 标签:devexpress |举报|字号 订阅 h ...
- qt布局嵌套_QDockWidget嵌套布局详解-实现Visual Studio布局
概述 许多工程软件,如Qt Creator,VS,matlab等,都是使用dock布局窗口,这样用户可以自定义界面,自由组合窗口. Qt的嵌套布局由QDockWidget完成,用Qt Creator拖 ...
- html中style布局放哪,CSS样式表与格式布局详解
样式表 CSS(Cascading Style Sheets 层叠样式表),作用是美化HTML网页. 内联样式表: 例: 内联样式表 内嵌样式表:必须写在head标签里 例: p { 样式;} he ...
- (淘宝无限适配)移动手机端rem布局详解(转载非原创)
https://www.cnblogs.com/well-nice/p/5509589.html (淘宝无限适配)手机端rem布局详解(转载非原创) 从网易与淘宝的font-size思考前端设计稿与工 ...
- flutter页面布局HTML,Flutter开发实战初级(2)页面布局详解
初级根底系列 Flutter开发实战初级(1)ListView详解 Flutter开发实战初级(2)布局详解 项目实战系列 Flutter开发实战 高仿微信(1)主页 Flutter开发实战 高仿微信 ...
- grid layout网格布局详解
grid layout网格布局详解 什么是grid layout grid的特点 grid css属性的基础知识 创建一个grid布局 创建一个网格 隐性网格与显性网格 尺寸单位fr repeat函数 ...
- tkinter-grid布局详解
前文tkinter-pack布局详解介绍了pack布局,相信对tkinter的布局套路有了一定的了解.本文将介绍另一种布局类grid. 同样,展示布局类与控件类的类间关系: 文章目录 grid 默认分 ...
- Android开发重点难点1:RelativeLayout(相对布局)详解
前言 啦啦啦~博主又推出了一个新的系列啦~ 之前的Android开发系列主要以完成实验的过程为主,经常会综合许多知识来写,所以难免会有知识点的交杂,给人一种混乱的感觉. 所以博主推出"重点难 ...
最新文章
- python 得到文件行数
- 网站常见攻击与防御汇总
- 17年前存款11万,取款时银行以销户为由拒绝,法院判银行全额赔付
- IntelliJ IDEA:文件的路径本该是”\“,却变成了”¥“
- 实验三:跟踪分析Linux内核的启动过程
- centos 6上安装使用saltstack以及基础管理
- Andrew ng 深度学习课程笔记
- 机器学习笔记(二):矩阵、环境搭建、NumPy | 凌云时刻
- 新宝解读大盘单边攀升突破3600点 大金融崛起
- 简单快速的运行 Zheng 平台(配置篇)
- 20220313_朴素贝叶斯
- Grubbs检验离群值——循环算法求出多个离群值
- ubuntu16.04成功安装 百度网盘 by deepin-wine-for-ubuntu
- 几个强大到没朋友的资源网站 个个都是精品
- 女生读计算机还是经济学,女生最吃香的十大专业你知道是什么吗?女生一定要懂...
- 新基建搭台,城市智能体唱戏 广西开启数字经济新篇章
- JAVA工具类ObjectUtils.Null
- Matplotlib subplot2grid()函数详解
- UE4Android聚光灯投影,ue4商城资源Volumetric Spotlight with Shadow带阴影的体积聚光灯
- java replace stringbuilder_2020年最新java面试题库(部分)
热门文章
- 手机视频监控直播系统是如何实现的?需要满足哪些条件?
- 解决W5500,DHCP获取IP地址失败的问题,移植官方例程需要特别注意!!!
- 编程思想-编程范式-编程思想是一组世界观和方法论-(初识范式——程序王国中的世界观与方法论)...
- Codeforces Round 701 Multiples and Power Differences
- 组态王 6.55 启停plc_成套设备PLC编程深圳PLC编程
- 什么是 DOORS?
- Java浅拷贝和深拷贝
- 【小程序源码】经典语录大全多种分类语录
- FDTD Solutions自学整理笔记入门教程(2):PML
- 百度杀毒+7654联盟