天天看點

百分比适配

 首先,需要添加 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:百分比表示頂部的間隔

下載下傳位址:

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