Android Percentlayout百分比布局

来源:互联网 发布:贵州浪人网络投诉 编辑:程序博客网 时间:2024/06/07 09:21

均支持以下属性:

·        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/

简单实用