android PercentFrameLyout 百分比布局 使用及注意事项
来源:互联网 发布:win10磁盘优化有什么用 编辑:程序博客网 时间:2024/05/21 09:33
简述:
PercentFrameLyout——是android团队新开发的一种布局方式,其特点是百分比方式控制控件的大小。
PercentFrameLyout另外继承FrameLyout特性,所有控件都默认摆放在布局的左上角。
元素属性:
LinearLayout 和 PercentFrameLyout 对比:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView app:layout_heightPercent="50%" app:layout_weightPercent="50%"/>
PercentFrameLyout 主要使用app:layout_heightPercent 和 app:layout_weightPercent 设置控件大小,当然也可以内置的使用android:layout_width跟android:layout_height。
如何使用PercentFrameLyout:
使用PercentFrameLyout很简单,只需要在app/build.gradle文件,在dependencise闭包中添加依赖,如下内容:
dependencies { compile 'com.android.support:percent:25.3.0' //只需添加依赖 }
需要注意的是SDK版本问题 ,另外奉上PercentFrameLyout的Github开源:点击打开链接。
比如现在最新版本需要↓↓↓
示范代码:
<?xml version="1.0" encoding="utf-8"?><android.support.percent.PercentFrameLayout 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/button" android:gravity="center" android:layout_gravity="left|top" android:background="#0f0" app:layout_widthPercent="50%" app:layout_heightPercent="50%" android:text="左上角" /> <TextView android:id="@+id/button2" android:gravity="center" android:background="#00f" android:layout_gravity="right|top" app:layout_widthPercent="50%" app:layout_heightPercent="50%" android:text="右上角" /> <TextView android:id="@+id/button3" android:gravity="center" android:background="#f00" android:layout_gravity="left|bottom" app:layout_widthPercent="50%" app:layout_heightPercent="50%" android:text="左下角"/> <TextView android:id="@+id/button4" android:gravity="center" android:background="#ff0" android:layout_gravity="right|bottom" app:layout_widthPercent="50%" app:layout_heightPercent="50%" android:text="右下角"/></android.support.percent.PercentFrameLayout>
总结:
可以看出我们使用了PercentFrameLyout不是内置系统的SDK当中,需要完整的包名路径写出,另外还必须定义app的命名空间,才可以使用PercentFrameLyout布局元素:
android.support.percent.PercentFrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
0 0
- android PercentFrameLyout 百分比布局 使用及注意事项
- Android百分比布局的使用
- Android百分比布局使用小坑一个
- Android 百分比布局支持库使用
- Android 百分比布局库的使用
- android 百分比布局percentFrameLayout,percentRelativeLayout的使用
- Android 百分比布局(percent-support-lib)的使用及源码详解
- Android 支持百分比布局
- Android支持百分比布局
- Android百分比布局初探
- Android百分比布局:PercentRelativeLayout
- Android百分比布局:PercentFrameLayout
- Android 百分比布局
- android 百分比layout布局
- Android百分比布局
- android 百分比布局
- Android 百分比布局库
- Android 百分比布局揭秘
- 小虎解读2017年最新的计算机专业技术人才职称评定国家政策
- 响应式布局,宽度自适应
- C++中new和delete的使用.c
- 一筐鸡蛋 1个1个拿……弱智题
- Matlab计算《概率论与数理统计辅导讲义》中与答案不一致的定积分
- android PercentFrameLyout 百分比布局 使用及注意事项
- python 中 str 拾遗
- Netty测试例子
- 一些笔记
- 【HTML】一句话新闻
- Problem 1060 Fibonacci数列
- 递归函数理解
- spring配置quartz 多任务
- 在centOS6.8下配置MATLAB与C混编环境