PercentLayout
- coding
- android
- ui
简介
布局适配神器,像css一样为控件设置长宽百分比,鲁棒性很强。
导入
PercentLayout是 Google 的开源项目,此处使用 @hongyangAndroid 的扩展库。
通过以下语句导入:
compile 'com.zhy:percent-support-extends:1.1.1'
使用
-
最外层需要用 percentLayout 嵌套,内层的
percentLayout才能生效。 -
需要引入命名空间 app 。
-
percentLayout 提供了三种布局:
PercentLinearLayout,PercentRelativeLayout,PercentFrameLayout。 -
使用
app:layout_widthPercent或app:heightPercent属性来设置宽度和高度,其width/height只需要设置成wrap_content即可。 -
使用
xx%w来设置为父控件宽度的某个百分比,使用xx%h来设置为父控件高度的某个百分比。
效果

< Later post
No earlier post >