- 浏览: 5770158 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
虽然有很多的布局可以在 Android 应用程序开发的世界供我们使用,但我们总是只用这三种布局:
LinearLayout, RelativeLayout and FrameLayout。
不管怎么说在用 RelativeLayout 和 FrameLayout 的时候总有一些问题,因为你不能设置子视图的百分比程度。
只有两种方法可能做到
1. 布局在 LinearLayout 里并用它的 layout_weight 布局参数;
2. 在 Java 代码中重写 onMeasure 方法来实现。
举个例子,如果我想在 RelativeLayout 里放一个简单的红色矩形,它是在顶部,并且距离左边的 5% 的位置,宽度为屏幕的25%。我们的代码可以这样写:
这是结果:
你会注意到这样的代码应该是非常复杂的。与此同时,这些控件也用视图和 LinearLayout 填充着,我们可以把它们看成是一种浪费。
这将不再是一个问题啦,因为在前几天 Android M 宣布了它的名字:棉花糖(Marshmallow),Android 团队推出了许多支持库去帮助开发者与碎片化的战斗!其中之一就是 百分比支持库(Percent Support Library) ,它具备的能力是用百分比去设置 RelativeLayout 和 FrameLayout 的尺寸!
你好,百分比支持库
这个库是非常容易使用的,因为它就如同 RelativeLayout 和 FrameLayout 一样我们都熟悉,只是有一些额外的功能。
首先,因为百分比支持库是随着 Android Support Library 23 一起的,所请确保你已经在 SDK Manager 中的 Android Support Library 更新了最新的版本。然后在build.gradle文件中添加下面这样的依赖:
compile 'com.android.support:percent:23.0.0'
现在,在使用老的 RelativeLayout 和 FrameLayout 做替换,只需要简单的将他们各自切换到android.support.percent.PercentRelativeLayout和android.support.percent.PercentFrameLayout。这里有9个布局参数可以使用:
layout_widthPercent: 用百分比来表示宽度,比如:app:layout_widthPercent="25%"
layout_heightPercent: 用百分比来表示高度
layout_marginPercent: 用百分比来表示 Margin
其余的是用百分比来表示每个 margin 面
layout_marginLeftPercent
layout_marginRightPercent
layout_marginTopPercent
layout_marginBottomPercent
layout_marginStartPercent
layout_marginEndPercent
用PercentRelativeLayout,上面的代码例子就能这样来写了:
这是结果:
你可以看到结果是完全是一致的,而且具有更短更清晰的代码,此外,该空间现在没有填充其他布局,这就让性能达到了更好的程度。
实际上这本应该就是 Android 整体的一部分,但不幸的是,事实并非如此。把它填加到原生Android 的RelativeLayout/FrameLayout 已经太迟了,因为用户用的设备都是老的操作系统版本,不可能支持使用这个功能。所以这就是为什么 Android 团队决定把它作为一个支持库来发布,我支持这个主意。
LinearLayout, RelativeLayout and FrameLayout。
不管怎么说在用 RelativeLayout 和 FrameLayout 的时候总有一些问题,因为你不能设置子视图的百分比程度。
只有两种方法可能做到
1. 布局在 LinearLayout 里并用它的 layout_weight 布局参数;
2. 在 Java 代码中重写 onMeasure 方法来实现。
举个例子,如果我想在 RelativeLayout 里放一个简单的红色矩形,它是在顶部,并且距离左边的 5% 的位置,宽度为屏幕的25%。我们的代码可以这样写:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="20"> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" /> <View android:layout_width="0dp" android:layout_height="100dp" android:layout_weight="5" android:background="#ff0000" /> </LinearLayout> </RelativeLayout>
这是结果:
你会注意到这样的代码应该是非常复杂的。与此同时,这些控件也用视图和 LinearLayout 填充着,我们可以把它们看成是一种浪费。
这将不再是一个问题啦,因为在前几天 Android M 宣布了它的名字:棉花糖(Marshmallow),Android 团队推出了许多支持库去帮助开发者与碎片化的战斗!其中之一就是 百分比支持库(Percent Support Library) ,它具备的能力是用百分比去设置 RelativeLayout 和 FrameLayout 的尺寸!
你好,百分比支持库
这个库是非常容易使用的,因为它就如同 RelativeLayout 和 FrameLayout 一样我们都熟悉,只是有一些额外的功能。
首先,因为百分比支持库是随着 Android Support Library 23 一起的,所请确保你已经在 SDK Manager 中的 Android Support Library 更新了最新的版本。然后在build.gradle文件中添加下面这样的依赖:
compile 'com.android.support:percent:23.0.0'
现在,在使用老的 RelativeLayout 和 FrameLayout 做替换,只需要简单的将他们各自切换到android.support.percent.PercentRelativeLayout和android.support.percent.PercentFrameLayout。这里有9个布局参数可以使用:
layout_widthPercent: 用百分比来表示宽度,比如:app:layout_widthPercent="25%"
layout_heightPercent: 用百分比来表示高度
layout_marginPercent: 用百分比来表示 Margin
其余的是用百分比来表示每个 margin 面
layout_marginLeftPercent
layout_marginRightPercent
layout_marginTopPercent
layout_marginBottomPercent
layout_marginStartPercent
layout_marginEndPercent
用PercentRelativeLayout,上面的代码例子就能这样来写了:
<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 app:layout_widthPercent="25%" android:layout_height="100dp" app:layout_marginLeftPercent="5%" android:background="#ff0000" /> </android.support.percent.PercentRelativeLayout>
这是结果:
你可以看到结果是完全是一致的,而且具有更短更清晰的代码,此外,该空间现在没有填充其他布局,这就让性能达到了更好的程度。
实际上这本应该就是 Android 整体的一部分,但不幸的是,事实并非如此。把它填加到原生Android 的RelativeLayout/FrameLayout 已经太迟了,因为用户用的设备都是老的操作系统版本,不可能支持使用这个功能。所以这就是为什么 Android 团队决定把它作为一个支持库来发布,我支持这个主意。
发表评论
-
利用广播实现强制下线功能
2016-12-28 10:45 1413最近一口气买 ... -
ViewDragHelper行为测试
2015-08-12 17:36 2688只是简单记录一下 以后可能会实现一些效果 import ... -
android5.x之Palette调色板
2015-07-17 10:30 3281Palette类可以分析一张图片,取出这张图片的特征色,然后为 ... -
使用ClipboardManager剪贴板实现复制粘贴功能
2015-04-10 14:39 3728经常要使用复制粘贴的功能,比如长安一个TextView弹出一个 ... -
LocationListener监听位置变化,当进入到某一距离内时发出提醒
2014-08-19 15:03 7623项目中需要这样的要求: 启动一个服务一直在背后监听当前位置变化 ... -
Android下集成FacebookSDk到项目并发表评论
2013-08-28 14:36 4821项目中需要发表自己的评论到Facebook,需要集成Faceb ... -
MediaRecorder录音,MediaPlayer播放
2013-05-23 09:53 7462直接看代码 import java.io.DataOutp ... -
Notification的基本用法
2013-05-22 11:52 5909android4.0以前: private static ... -
android音频、视频、拍照基础操作
2013-03-27 11:55 2762播放音乐和视频用的是类:MediaPlayer 刻录声音和视 ... -
tabhost通过手势滑动切换activity
2013-02-18 17:59 11096package com.mars.mp3player; ... -
VideoView简单视频播放
2013-02-17 17:17 9238只是上上手而已的例子。 package com.chen ... -
android 再按一次后退键退出应用程序
2012-06-15 21:51 4056private static Boolean isExit ... -
AlarmManager全局定时器/闹钟
2012-02-01 10:11 5816http://407827531.iteye.com/blog ... -
倒计时的CountDownTimer
2011-12-23 13:06 31132直接看这里吧,我只是搬运工。 定时执行在一段时候后停止的倒计 ... -
Android流量统计TrafficStats类的使用
2011-12-06 16:25 26373对于Android流量统计来说在2.2版中新加入了Traffi ... -
ScrollView当显示超出当前页面时自动移动到最底端
2011-09-01 09:42 16940卷轴视图(ScrollView)是指当拥有很多内容,一屏显示不 ... -
在SurfaceView上拖动一架飞机
2011-08-23 12:40 2871接上一篇在SurfaceView上拖动一张小图片 什么叫拖动飞 ... -
在SurfaceView上拖动一张小图片
2011-08-22 18:20 5182用手指随便拖。这里采用了线程去绘制,其实也可以在onTouch ... -
用getIdentifier()获取资源Id
2011-07-28 22:36 10708做项目过程中遇到一个问题,从数据库里读取图片名称,然后调用图片 ... -
利用VelocityTracker监控对触摸的速度跟踪
2011-07-28 22:12 10014VelocityTracker就是速度跟踪的意思。我们可以获得 ...
相关推荐
android8.0 sdk没有percent百分比布局库 ,这里吧三个源文件打包上传,下载下来粘贴到安卓SDK的support文件夹下,应该就可以使用了
Android 百分比布局库(percent-support-lib)
Android百分比布局Demo android.support.percent.PercentRelativeLayout
百分比布局<android.support.percent.PercentLinearLayout android:id="@+id/tv_solid_number_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft=...
Android屏幕适配之Google百分比布局库的扩展在项目中引用 compile 'com.zhy:percent-support-extends:1.1.1'依赖, 主要有三个用于布局的类 ...具体使用看源码
博客地址 http://blog.csdn.net/sbsujjbcy/article/details/46693999
Eclipse的Android百分比支持库我修改了该库以在Eclipse中使用。 它将很快在android dev网站上进行记录,因此这只是概念的证明:) 您可以查看官方文档参考该库同时提供基于百分比的布局,水平和垂直。简单的结果复杂的...
google官方百分比布局,eclipse可用,将项目导入eclipse,依赖该项目即可.android studio还是从官网下吧。
Android Percent Support Lib Sample :triangular_ruler::triangular_ruler::triangular_ruler: I made a sample of the new percent support library. You can check official docs reference here and here. ...
文章目录一、简述二、google推荐的百分比布局的使用方式三、实现3.1 创建属性文件3.2 解析3.3 计算并设置百分比布局四、使用五、完整代码六、注意 一、简述 百分比布局适配,就是以父容器的尺寸作为基准,在view的...
android-percent-layout-builder 百分比布局的ui设计器
### Android-Percent-Layout-Sample这是使用android百分比布局的示例。 在你可以找到它添加支持库dependencies { compile 'com.android.support:percent:22.2.0'} ###布局< RelativeLayout xmlns : android = ...
这就是一个百分比布局项目,源码android-percent-support-lib-sample,谷歌最新的百分比布局库的示例项目。其实LinearLayout的layout_weight也能实现百分比效果,不过这个更直接。
百分比布局 屏幕适配 dependencies { compile 'com.android.support:percent:22.2.0' } 新的容器有了一些设置百分比的属性,下面我们来了解一下: layout_widthPercent 设置控件宽度为父容器的宽的百分比 layout_...
下面的示例使用ConstraintLayout创建,因为百分比支持库已从API级别26.0.0开始弃用。 整合与范例 本示例使用ConstraintLayout构建xml UI。 帮助避免嵌套布局的开销,从而提高性能。 非常棒!!! 脚步: 将以下...
除此之外,它可以设置一组按钮作为菜单展示,支持上下左右四个方位显示,更方便的是可以在代码中动态的添加按钮或者移除按钮。 引入 dependencies { compile 'com.cpacm:floatingmusicmenu:1.0.0' } 具体使用 ...