andriod百分比布局
来源:互联网 发布:openstack 源码分析 编辑:程序博客网 时间:2024/05/16 18:45
日常开发中我们使用LinearLayout来进行开发布局,并且活用layout-weight属性会为我们的开发节省很多得时间,并且一定程度上解决了开发中的适配问题。但是LinearLayout的局限在于我们只能有两个方向上的摆放,不怎么灵活。这个时候我们会去怀念RelativeLayout。不过RelativeLayout却没有layout-weight这样的布局参数可以设置。确实很让人头疼,这个时候SDK提出了一种全新的布局方式,百分比布局。
分为两种
- PercentFrameLayout
- PercentRelativeLayout
可以看到几乎只是在帧布局和相对布局上做了扩展。
使用
这里以PercentRelativeLayout为例。
添加依赖
在APP模块下添加一个依赖。
compile 'com.android.support:percent:23.4.0'
至于版本根据合适选择就好。添加后需要同步一下项目。
直接使用
<?xml version="1.0" encoding="utf-8"?><android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/activity_main"android:layout_width="match_parent"android:layout_height="match_parent"><TextView android:layout_centerInParent="true" android:background="#2d7d9a" android:gravity="center" android:text="Center" app:layout_heightPercent="50%" app:layout_widthPercent="50%" /><TextView android:background="#2d7d9a" android:gravity="center" android:text="left|top" app:layout_heightPercent="25%" app:layout_widthPercent="25%" /><TextView android:layout_alignParentRight="true" android:background="#2d7d9a" android:gravity="center" android:text="right|top" app:layout_heightPercent="25%" app:layout_widthPercent="25%" /><TextView android:layout_alignParentBottom="true" android:background="#2d7d9a" android:gravity="center" android:text="left|bottom" app:layout_heightPercent="25%" app:layout_widthPercent="25%" /><TextView android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:background="#2d7d9a" android:gravity="center" android:text="right|bottom" app:layout_heightPercent="25%" app:layout_widthPercent="25%" /></android.support.percent.PercentRelativeLayout>
注意点
- 写出完整的包名
- 需要声明一个命名空间
- 使用的是layout_widthPercent属性
- 如果AndroidStudio版本比较低是无法预览的,但是不影响结果
0 0
- andriod百分比布局
- 百分比布局
- 百分比布局
- 百分比布局
- 百分比布局
- 百分比布局
- 百分比布局
- 百分比布局
- 百分比布局
- Andriod布局
- Andriod 布局
- Andriod布局
- CSS 使用百分比布局
- RelativeLayout实现百分比布局
- CSS百分比布局
- Android 支持百分比布局
- Android支持百分比布局
- Android百分比布局初探
- 有关字符串的问题
- LDA主题模型评估方法--Perplexity
- HashSet和LinkedHashSet练习
- STM32 端口复用&重映射(USART Remap)
- stm32串口通信调试总结
- andriod百分比布局
- 剑指Offer(第二版)面试题6:从尾到头打印链表
- 经典排序——基数排序LSD——C语言版
- 《天使爱美丽》附百度云盘链接
- 第3篇:angularJS使用ui-router的嵌套路由配置
- 使用OpenCL+OpenCV实现图像旋转(二)
- Linux中执行shell脚本的4种方法总结
- curl的超时时间设置
- 变量和基本类型---C++ 基础