Android Percent Layout 安卓百分比布局

来源:互联网 发布:个人业务介绍源码 编辑:程序博客网 时间:2024/05/29 04:34

谷歌官方支持按照百分比来设置布局的宽高


支持PercentRelativeLayout和PercentFrameLayout,分别继承自RelativeLayout和FrameLayout

均支持以下属性:

  • layout_widthPercent
  • layout_heightPercent
  • layout_marginPercent
  • layout_marginLeftPercent
  • layout_marginTopPercent
  • layout_marginRightPercent
  • layout_marginBottomPercent
  • layout_marginStartPercent
  • layout_marginEndPercent
效果图:





如何使用:

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

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

布局文件

PercentRelativeLayout

<android.support.percent.PercentRelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent">    <View        android:id="@+id/top_left"        android:layout_width="0dp"        android:layout_height="0dp"        android:layout_alignParentTop="true"        android:background="#ff44aacc"        app:layout_heightPercent="20%"        app:layout_widthPercent="70%" />    <View        android:id="@+id/top_right"        android:layout_width="0dp"        android:layout_height="0dp"        android:layout_alignParentTop="true"        android:layout_toRightOf="@+id/top_left"        android:background="#ffe40000"        app:layout_heightPercent="20%"        app:layout_widthPercent="30%" />    <View        android:id="@+id/bottom"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_below="@+id/top_left"        android:background="#ff00ff22"        app:layout_heightPercent="80%" /></android.support.percent.PercentRelativeLayout>


非常简单易用!


GitHub示例:

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

官方开发文档:

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




1 0
原创粉丝点击