百分比适配

 首先,需要添加 com.android.support:percent:24.1.1 包,版本随意
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:percent:24.1.1'}

 这个包给我们提供了 PercentRelativeLayout以及 PercentFrameLayout两种布局,
  支持的属性有 layout_widthPercent layout_heightPercent 、 
  layout_marginPercent layout_marginLeftPercent 、 
   layout_marginTopPercent layout_marginRightPercent 、 
  layout_marginBottomPercent layout_marginStartPercent layout_marginEndPercent

打开下载后的函数库,发现其中主要包含三个类。
PercentFrameLayout、PercentRelativeLayout、PercentLayoutHelper
大部分的百分比实现逻辑都在PercentLayoutHelper这个类中,首先我们需要知道,PercentFrameLayout、PercentRelativeLayout分贝继承于FrameLayout、RelativeLayout。原有的属性和方法都是可以使用的。同时PercentHelper还对其做了百分比布局的扩展,在xml文件中,增加了如下属性配置。
  • heightPercent :百分比表示高度
  • widthPercent :百分比表示宽度
  • marginBottomPercent :百分比表示底部的间隔
  • marginEndPercent:百分比表示距离最后一个View之间的间隔
  • marginLeftPercent:百分比表示左边的间隔
  • marginPercent :百分比表示View之间的间隔
  • marginRightPercent:百分比表示右边的间隔
  • marginStartPercent:百分比表示距离第一个View之间的间隔
  • marginTopPercent:百分比表示顶部的间隔

下载地址:


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值