android support Percent支持库开发
Android的布局支持百分比的设置进行开发,来学习如何去实现它,不过看起来会像网页的设置,比如宽度的设置属性是`layout_widthPercent`。在此之前,我们一般都会设置Linearlayout的weight权重来实现布局间的比例大小。
Percent support Library提供了两个新的类:
1.PercentRelativeLayout
2.PercentFrameLayout
创建新项目
创建一个新的项目来测试,修改`build.gradle`,需要引入以下库
`applyplugin:'com.android.application'
android {
compileSdkVersion23
buildToolsVersion"23.0.0"
defaultConfig {
applicationId"com.android.chaowen.percentdemo1"
minSdkVersion7
targetSdkVersion22
versionCode1
versionName"1.0"
}
buildTypes {
release {
minifyEnabledfalse
proguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir:'libs',include: ['*.jar'])
compile'com.android.support:support-annotations:23.0.0'
compile'com.android.support:appcompat-v7:23.0.0'
compile'com.android.support:design:23.0.0'
compile'com.android.support:percent:23.0.0'
}
创建布局
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> android:id="@+id/first" android:background="@color/sa_green_dark" app:layout_heightPercent="50%" app:layout_marginLeftPercent="25%" app:layout_marginTopPercent="25%" app:layout_widthPercent="50%" /> android:layout_width="0dp" android:layout_height="32dp" android:layout_alignLeft="@id/first" android:layout_alignStart="@id/first" android:layout_alignRight="@id/first" android:layout_alignEnd="@id/first" android:layout_below="@id/first" android:layout_marginTop="8dp" android:background="@color/light_grey" />

比例大小是通过`heightPercent`和`widthPercent`属性来设置百分比大小值。完全属于`RelativeLayout`的扩展类,值得一提的是,
不再需要设置`layout_width`和`layout_height`,注意了,这是新的库使用方法,因为这两个属性会被自动加入了。
百度比也可以用于设置边距。唯一区别的只是采取了百分比值。
最后一点需要注意,在第二个view,并没有直接设置比例的大小,但是它的位置是相对于第一个view.
android support Percent支持库开发的更多相关文章
- As环境下添加android support library依赖库
2015年的google大会上,google发布了新的Android Support Design库的新组件之一,以此来全面支持Material Design 设计风格的UI效果,为了可以使用这些新颖 ...
- Android百分比布局支持库介绍——com.android.support:percent(转)
转载自http://www.apkbus.com/forum.php?mod=viewthread&tid=244752&extra=&_dsign=0b699c42 在此之前 ...
- Android添加百分比布局库时显示Failed to resolve: com.android.support.percent:问题
这是看第一行代码中遇到的问题,要添加百分比布局库的依赖时要在app下的bulid.gradle添加以下代码 implementation fileTree(dir:'libs',include:['* ...
- (转)Android Support Percent百分比布局
一.概述 周末游戏打得过猛,于是周天熬夜码代码,周一早上浑浑噩噩的发现 android-percent-support-lib-sample(https://github.com/JulienGeno ...
- Android Studio com.android.support:percent 导入错误 - 转
看第一行代码(第二版的)书,讲了一个关于PercentFrameLayout和PercentRelativeLayout的部分,书上在build.gradle中导入了com.android.suppo ...
- Android support library支持包常用控件介绍(一)
谷歌官方推出Material Design 设计理念已经有段时间了,为支持更方便的实现Material Design设计效果,官方给出了Android support design library 支 ...
- Android support library支持包常用控件介绍(二)
谷歌官方推出Material Design 设计理念已经有段时间了,为支持更方便的实现 Material Design设计效果,官方给出了Android support design library ...
- Android百分比布局支持库(android-percent-support)
Android中提供了五种布局,其中用的最多的就是:LinearLayout, RelativeLayout 和 FrameLayout这三种布局,在对某一界面进行布局时最先想到也是通过这三种来布局的 ...
- [原]ffmpeg编译android 硬解码支持库 libstagefright
最近花了一天时间将ffmpeg/tools/build_stagefright执行成功,主要是交叉编译所需要的各种动态库的支持没链接上,导致各种报错,基本上网络上问到的问题我都碰到了,特此记录下来. ...
随机推荐
- 学习Slim Framework for PHP v3 (四)--get()是怎么加进去的?
看看官网加粗的一句话: At its core, Slim is a dispatcher that receives an HTTP request, invokes an appropriate ...
- 人情世故&潜规则
大凡成功的牛人,无一例外都明白这一点.他们读懂了社会的本质和人际交往的潜规则,知道对方需要什么,知道对方脑子里在想什么.你几乎看不见他奔波劳碌,但是在不动声色中,他就已经实现人生目标.他们成功的密码是 ...
- Python调用Webservice、访问网页
昨天在调试Webservice的时候,由于不想写测试程序,就想用Python访问Webservice,结果还是相当的麻烦.远没有VSIDE用的方便 不得不说VS还是很强大的,人性化做的很好,不需要你看 ...
- 【转载】分析商品日均销量(DMS)对促销商品选择的意义
江苏省常州市信特超市有限公司副总经理高晓颖 随着中国零售业的进一步的开放,竞争日趋激烈,促销活动在日常经营中已经成为不可缺少的一部分,频繁的促销活动的开展,零售业经营管理者越来越觉得促销商品的选择难度 ...
- 增强for循环用法___ArrayList数组实现使用下标最好,LinkedList使用增强型的(转载)
总结: 1.For-Each循环的缺点:丢掉了索引信息. 当遍历集合或数组时,如果需要访问集合或数组的下标,那么最好使用旧式的方式来实现循环或遍历,而不要使用增强的for循环,因为它丢失了下标信息. ...
- mysql中权限参数说明
1 授权表范围列的大小写敏感性+--------------+-----+-----+---------+----+-----------+------------+| 列 |Ho ...
- QtPropertyBrowser+vs2010的安装与配置(转)
这一篇文章有些问题,后又写了一篇,地址是http://www.cnblogs.com/aminxu/p/4552410.html 转自http://blog.csdn.net/jingwenlai_s ...
- tar命令: 对某目录文件打tar包时,排除指定的目录或文件
如某当前目录存在以下文件或目录: 1.txt2.txt3.txtdir1dir2my2015.tarmy2016.tar 若要对当前目录除1.txt 和dir1.tar外,打包tar 步骤一.建立e ...
- 三款精美的html5及css3的源码插件
1.HTML5 3D爱心动画 晚来的七夕礼物 七夕情人节刚过,今天小编却在国外的网站上看到一个利用HTML5和CSS3制作的3D爱心动画,莫非老外也过七夕?当然小编还是将这款HTML5 3D爱心动画收 ...
- 控制反转 (inversion of control)
The inversion of control (IoC) pattern is abstract; it says that one should move dependency creation ...