ViewOverlay 浮层
ViewOverlay 看似挺陌生的,其实android在4.3的时候就已经供给了,它是view上面的的一个浮层,这个浮层与当前View视图大小一致,可以理解一个上下两层的楼房,但是上层的内容并不影响整个布局.
API:添加覆盖
/*** Adds a Drawable to the overlay. The bounds of the drawable should be relative to* the host view. Any drawable added to the overlay should be removed when it is no longer* needed or no longer visible.** @param drawable The Drawable to be added to the overlay. This drawable will be* drawn when the view redraws its overlay.* @see #remove(Drawable)*/public void add(Drawable drawable) {mOverlayViewGroup.add(drawable);}
API: 移除覆盖
/*** Removes the specified Drawable from the overlay.** @param drawable The Drawable to be removed from the overlay.* @see #add(Drawable)*/public void remove(Drawable drawable) {mOverlayViewGroup.remove(drawable);}
API: 清除所有覆盖
/*** Removes all content from the overlay.*/public void clear() {mOverlayViewGroup.clear();}
API: 覆盖是否为空
boolean isEmpty() {return mOverlayViewGroup.isEmpty();}
ViewOverlay还有个子类,主要提供给ViewGroup的,增加了两个方法
add(view) ;remove(view) 添加浮层视图和移除浮沉视图
* @param view The View to be added to the overlay. The added view will be* drawn when the overlay is drawn.* @see #remove(View)* @see ViewOverlay#add(Drawable)*/public void add(View view) {mOverlayViewGroup.add(view);}/*** Removes the specified View from the overlay.** @param view The View to be removed from the overlay.* @see #add(View)* @see ViewOverlay#remove(Drawable)*/public void remove(View view) {mOverlayViewGroup.remove(view);}
最大的作用就是穿越层次
下面将会给出例子:
1:移动的范围 左边扩展范围为整个窗体,而右边默认属于父亲范围大小
private void overlayWindow(final View v) {if (Build.VERSION.SDK_INT < 18) return;final ViewGroup group = ((ViewGroup) getWindow().getDecorView());group.getOverlay().add(v);//简单位移动画ObjectAnimator anim = ObjectAnimator.ofFloat(v, "translationY", group.getHeight());anim.setDuration(2000);anim.addListener(new Animator.AnimatorListener() {@Overridepublic void onAnimationStart(Animator animation) {}@Overridepublic void onAnimationEnd(Animator animation) {group.getOverlay().remove(v);}@Overridepublic void onAnimationCancel(Animator animation) {group.getOverlay().remove(v);}@Overridepublic void onAnimationRepeat(Animator animation) {}});anim.start();}private void animWiew(View v) {ObjectAnimator anim = ObjectAnimator.ofFloat(v, "translationY", 15 * (v.getHeight()));anim.setDuration(2000);anim.start();}
可以看到左边的移动返回为整个窗体,而右边移动返回属于红色区域(默认父亲窗体大小)
例子2:展现view默认的移动范围,是他父亲的大小范围
private void overlayWindow2(final View v) {if (Build.VERSION.SDK_INT < 18) return;final ViewGroup group = (ViewGroup) v.getParent();ObjectAnimator anim = ObjectAnimator.ofFloat(v, "translationY", group.getHeight());anim.setDuration(2000);anim.start();}
这里并未添加浮层
例子3: 凌波微步的效果:
/*** 先展示一个消失动画* <p/>* 再在窗体中位移* <p/>* 凌波微步的效果** @param v*/private void CombinationOverlay(final View v) {if (Build.VERSION.SDK_INT < 18) return;ObjectAnimator fade = ObjectAnimator.ofFloat(button3, "alpha", 1f, 0f);fade.setDuration(1000);fade.addListener(new Animator.AnimatorListener() {@Overridepublic void onAnimationStart(Animator animation) {}@Overridepublic void onAnimationEnd(Animator animation) {FrameLayout fram_greent = (FrameLayout) findViewById(R.id.fram_greent);v.setAlpha(1.0f);fram_greent.getOverlay().add(v);final ViewGroup group = ((ViewGroup) getWindow().getDecorView());ObjectAnimator anim = ObjectAnimator.ofFloat(v, "translationY", -group.getHeight());anim.setDuration(2000);anim.addListener(new Animator.AnimatorListener() {@Overridepublic void onAnimationStart(Animator animation) {}@Overridepublic void onAnimationEnd(Animator animation) {group.getOverlay().remove(v);}@Overridepublic void onAnimationCancel(Animator animation) {group.getOverlay().remove(v);}@Overridepublic void onAnimationRepeat(Animator animation) {}});anim.start();}@Overridepublic void onAnimationCancel(Animator animation) {}@Overridepublic void onAnimationRepeat(Animator animation) {}});fade.start();}
ViewOverlay 浮层相关推荐
- 浮层java_通过遮罩层实现浮层DIV登录的js代码
摘要:这篇JavaScript栏目下的"通过遮罩层实现浮层DIV登录的js代码",介绍的技术点是"浮层DIV.JS代码.div.遮罩层.登录.代码",希望对大家 ...
- Android之Android实现浮层的上下滑动(支持内部添加View)
前言 我K,今天居然是情人节,对于资深的单身狗来说,简直是个噩耗,今天注定是各种秀恩爱,心塞中.... 话题到此结束,管他什么情人节,今天给大家带来的是一个浮层的上下滑动,浮层滑动时分三种状态:全部显 ...
- 十二 手游开发神器 cocos2d-x editor 之游戏暂停悬浮层
进入游戏主场景,游戏需要临时暂停.重新选关.重新玩等等,所以玩家点击暂停按钮,弹出一个选择悬浮层,这一节我们来实现: 效果如下: 点击右上角游戏暂停: 返回回到开始界面: 代码下载:http://ww ...
- 得到目标元素距离视口的距离以及元素自身的宽度与高度(用于浮层位置的动态改变)...
以前所有操作都用弹窗弹个小层出来,然后最近整体换成了气泡风格,点哪里操作浮层就出现在哪里.我采用的是共用一个操作浮层,随元素位置而变换浮层的位置. 思路大概就是如下: 第一:确定浮层基于哪个元素定位 ...
- android 半浮层框架,GitHub - Jodragon/AnyLayer: Android稳定高效的浮层创建管理框架
AnyLayer Android稳定高效的浮层创建管理框架. 可取代系统自带Dialog/Popup/BottomSheet等弹窗,可实现单Activity架构的Toast提示,可定制任意样式的Gui ...
- android 蒙版图片带拖动_推荐一个好用小巧的Android引导蒙版(浮层)库
更新:目前该库已更新v2.0版本,修改了调用api,详细使用可以看:可能是最好用的Android引导层库 前言 每当一个项目开发一个新功能,总会想办法及时让用户得知有这样一个新功能,这时通常会采用引导 ...
- Android官方开发文档Training系列课程中文版:添加ActionBar之ActionBar浮层效果
原文地址 : http://android.xsoftlab.net/training/basics/actionbar/overlaying.html 浮层效果的ActionBar 默认情况下,Ac ...
- 流量劫持 —— 浮层登录框的隐患
传统的登录框 在之前的文章流量劫持危害详细讲解了 HTTP 的高危性,以至于重要的操作都使用 HTTPS 协议,来保障流量在途中的安全. 这是最经典的登录模式.尽管主页面并没有开启 HTTPS,但登录 ...
- Android实现浮层的上下滑动(支持内部加入View)
前言 我K.今天竟然是情人节.对于资深的单身狗来说,简直是个噩耗,今天注定是各种秀恩爱.心塞中.. .. 话题到此结束,管他什么情人节,今天给大家带来的是一个浮层的上下滑动,浮层滑动时分三种状态:所有 ...
最新文章
- 机械键盘恢复出厂fn_黑爵毛茸茸系列机械键盘评测
- 【Qt】打开现有 Qt 项目 ( 打开已存在的项目 | 运行打开的项目 )
- linux脚本重命名文件,shell脚本批量对文件改名(名字新旧不相关)
- 虚拟机linux如何扩大内存吗,如何扩大Vmware虚拟机中Ubuntu系统磁盘空间的方法
- grunt集成自动启动
- oracle各种查询语句
- API接口文档生成方案调研
- Python键鼠模拟,DNF自动刷图
- Android Studio搭建阿里云生活物联网平台自有品牌APP
- 20145212 罗天晨 MSF基础应用
- fastreport 横向打印多列
- 【学习求职必备】认真认识一下世界末日那年成立的“华为诺亚方舟实验室”...
- 张艾迪(创始人):世界最高级文明信仰
- 基于图像的虚拟试衣:CloTH-VTON:Clothing Three-dimensional reconstruction for Hybrid image-based Virtual Try-On
- android电视自动关机,android实现自动关机的具体方法
- cesium 实战记录(六)地图通用工具方法的封装
- 求职信 (application for employment)
- html图片自动移动代码是什么,html图片滚动代码
- linux centos livecd,定制自己的LiveCD,依托(centos)
- STM32驱动WS2812