Android Percent Layout 安卓百分比布局
2015-07-01 14:18
645 查看
谷歌官方支持按照百分比来设置布局的宽高。
支持PercentRelativeLayout和PercentFrameLayout,分别继承自RelativeLayout和FrameLayout
均支持以下属性:
效果图:
如何使用:
添加支持库到你的工程(Studio)
dependencies {
compile 'com.android.support:percent:22.2.0'
}
布局文件
<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/
支持PercentRelativeLayout和PercentFrameLayout,分别继承自RelativeLayout和FrameLayout
均支持以下属性:
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.PercentRelativeLayoutxmlns: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/
相关文章推荐
- Android中的数据格式化
- Android---- 获取当前应用的版本号和当前android系统的版本号
- External SD card with ext4 under Android (CM10.1)
- Activity与Fragment数据传递之Fragment从Activity获取数据 分类: Android 2015-07-01 14:12 17人阅读 评论(0) 收藏
- Android 区别普通Touch方法和Scroll
- Android 使用DexClassLoader要执行其他apk方法
- Android ListViewitem滑动出现删除按钮
- Android 4.1.2为通知栏添加wifi开关
- Android 的sp 和 wp 类模板 以及RefBase类
- android volley框架介绍
- Android Camera 使用小结
- Activity的四种启动模式和onNewIntent()
- 有关Android屏幕监听的问题
- Android四大组件
- android webview中调用了js的时候混淆注意事项
- Android Activity类中的finish()、onDestory()和System.exit(0) 三者的区别
- Android Fragment 你应该知道的一切
- Android 百分比布局库(percent-support-lib) 解析与扩展
- Android xxx is not translated in zh解决办法
- Android 4.1.2系统添加重启功能