Android官方终于支持按百分比来设置控件的宽和高了。有了这样的控件,写起来就比较方便了。其实LinearLayout的layout_weight也能实现百分比效果,不过这个更直接,更好用。这个百分比控件的出现,其实在另一方面也解决了部分屏幕适配的问题。
这个库提供了两种布局供大家使用,分别为:
PercentRelativeLayout和PercentFrameLayout,我们通过以往经验和名字就可以知道它们分别继承于RelativeLayout和FrameLayout两个容器类。
支持的属性如下:
layout_widthPercent、layout_heightPercent、
layout_marginPercent、layout_marginLeftPercent、
layout_marginTopPercent、layout_marginRightPercent、
layout_marginBottomPercent、layout_marginStartPercent、layout_marginEndPercent
运行效果如下:
使用说明:
1、首先记得在build.gradle添加:
compile 'com.android.support:percent:22.2.0’
2、布局文件如下:
xmlns:app="http://s