Android Percentlayout百分比布局

均支持以下属性:

·        layout_widthPercent

·        layout_heightPercent

·        layout_marginPercent

·        layout_marginLeftPercent

·        layout_marginTopPercent

·        layout_marginRightPercent

·        layout_marginBottomPercent

·        layout_marginStartPercent

·        layout_marginEndPercent

效果图:

 

 

如何使用:

添加支持库到你的工程(Studio

[java] view plain copy

  1. dependencies {  
  2.     compile 'com.android.support:percent:22.2.0'  
  3. }  


布局文件

PercentRelativeLayout

[html] view plain copy

  1. <android.support.percent.PercentRelativeLayout  
  2.     xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent">  
  6.   
  7.     <View  
  8.         android:id="@+id/top_left"  
  9.         android:layout_width="0dp"  
  10.         android:layout_height="0dp"  
  11.         android:layout_alignParentTop="true"  
  12.         android:background="#ff44aacc"  
  13.         app:layout_heightPercent="20%"  
  14.         app:layout_widthPercent="70%" />  
  15.   
  16.     <View  
  17.         android:id="@+id/top_right"  
  18.         android:layout_width="0dp"  
  19.         android:layout_height="0dp"  
  20.         android:layout_alignParentTop="true"  
  21.         android:layout_toRightOf="@+id/top_left"  
  22.         android:background="#ffe40000"  
  23.         app:layout_heightPercent="20%"  
  24.         app:layout_widthPercent="30%" />  
  25.   
  26.   
  27.     <View  
  28.         android:id="@+id/bottom"  
  29.         android:layout_width="match_parent"  
  30.         android:layout_height="0dp"  
  31.         android:layout_below="@+id/top_left"  
  32.         android:background="#ff00ff22"  
  33.         app:layout_heightPercent="80%" />  
  34. </android.support.percent.PercentRelativeLayout>  


GitHub示例:

https://github.com/JulienGenoud/android-percent-support-lib-sample

官方开发文档:

https://juliengenoud.github.io/android-percent-support-lib-sample/

简单实用


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值