百分比适配

来源:互联网 发布:iphone 贵吗 知乎 编辑:程序博客网 时间:2024/05/20 15:59
 首先,需要添加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_widthPercentlayout_heightPercent、 
  layout_marginPercentlayout_marginLeftPercent、 
  layout_marginTopPercentlayout_marginRightPercent、 
  layout_marginBottomPercentlayout_marginStartPercentlayout_marginEndPercent

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

下载地址:

http://blog.csdn.net/huningjun/article/details/47081519

 

原创粉丝点击