Android百分比布局
来源:互联网 发布:python帮助文档 编辑:程序博客网 时间:2024/05/16 11:37
2015的google大会发布了百分比布局,大大减少了android开发的适配量,最近使用了下百分比布局。
首先要引入百分比布局支持库:
新建一个工程,在xml中添加如下代码:
需要注意,百分比布局要加入下面这行代码
<span style="color:#FF6600;">xmlns:app="http://schemas.android.com/apk/res-auto"</span>
<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"></android.support.percent.PercentRelativeLayou在布局中添加如下三个view:
<pre name="code" class="html"><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"> <TextView android:id="@+id/tv1" android:layout_width="0dp" android:layout_height="0dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="10dp" android:background="#ff4040" app:layout_heightPercent="20%" app:layout_widthPercent="70%" android:gravity="center" android:text="tv1 父容器为屏幕"/> <TextView android:id="@+id/tv2" android:layout_width="match_parent" android:layout_height="0dp" android:layout_below="@id/tv1" android:background="#00ff00" app:layout_heightPercent="30%" app:layout_marginBottomPercent="10%" app:layout_marginLeftPercent="10%" app:layout_marginRightPercent="20%" app:layout_marginTopPercent="10%" android:gravity="center" android:text="tv2 父容器为屏幕"/> <android.support.percent.PercentRelativeLayout android:background="#000000" android:layout_width="match_parent" android:layout_height="200dp" android:layout_below="@id/tv2"> <TextView android:id="@+id/tv3" android:background="#00F3FF" android:layout_width="0dp" android:layout_height="0dp" android:layout_centerInParent="true" app:layout_heightPercent="20%" app:layout_widthPercent="70%" android:gravity="center" android:text="tv3 父容器为黑色部分" /> </android.support.percent.PercentRelativeLayout></android.support.percent.PercentRelativeLayout>
运行:
经验证发现此百分比是基于父容器。
0 0
- Android 支持百分比布局
- Android支持百分比布局
- Android百分比布局初探
- Android百分比布局:PercentRelativeLayout
- Android百分比布局:PercentFrameLayout
- Android 百分比布局
- android 百分比layout布局
- Android百分比布局
- android 百分比布局
- Android 百分比布局库
- Android 百分比布局揭秘
- Android 自定义百分比布局
- Android百分比布局
- android中的百分比布局
- Android百分比布局:PercentFrameLayout
- Android百分比布局:PercentRelativeLayout
- android百分比布局
- Android中的百分比布局
- 学习笔记—输出XML
- linux设备驱动--内核等待队列知识点---结合中断使用
- Pig安装及简单实例
- Grub 2:拯救你的 bootloader
- Zigzag Iterator
- Android百分比布局
- Animation分类及用法
- 【小松教你手游开发】【面试必读(编程基础)】开始构建三维图形引擎:点、向量和一些基本概念
- Linux 标准输入输出及重定向
- xutils3.0 的使用及demo
- ViewPager+Fragment取消预加载(延迟加载)
- 40+ Sublime Text 最佳插件汇总
- js split 的用法和定义 js split分割字符串成数组的实例代码
- 最简单的三角形