您的位置:首页 > 移动开发 > Android开发

Android Percent Layout 安卓百分比布局

2015-07-01 14:18 645 查看
谷歌官方支持按照百分比来设置布局的宽高。

支持PercentRelativeLayoutPercentFrameLayout,分别继承自RelativeLayoutFrameLayout

均支持以下属性:

layout_widthPercent

layout_heightPercent

layout_marginPercent

layout_marginLeftPercent

layout_marginTopPer
af58
cent

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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: