Android 新手引导蒙层效果实现
2017-01-06 14:40
489 查看
先上效果图:
这个效果一开始我是想直接让UI给个切图,后来发现这样不行,适配很差,达不到效果。所以就自己动手写代码,其实思路也很简单:在这个布局的父布局上面再手动添加一个view(通常LinearLayout比较方便),然后把这个linearlayout的背景设置成#88000000,之后就是给这个linearlayout动态增加子view,初步效果就能达到。
下面直接上代码:
public void showGuideView() {
如有不当的地方,还请指正!
这个效果一开始我是想直接让UI给个切图,后来发现这样不行,适配很差,达不到效果。所以就自己动手写代码,其实思路也很简单:在这个布局的父布局上面再手动添加一个view(通常LinearLayout比较方便),然后把这个linearlayout的背景设置成#88000000,之后就是给这个linearlayout动态增加子view,初步效果就能达到。
下面直接上代码:
public void showGuideView() {
View view = getWindow().getDecorView().findViewById(R.id.activity_main); if (view == null) return; ViewParent viewParent = view.getParent(); if (viewParent instanceof FrameLayout) { final FrameLayout frameParent = (FrameLayout) viewParent;//整个父布局 final LinearLayout linearLayout = new LinearLayout(this);//新建一个LinearLayout linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setBackgroundResource(#88000000);//背景设置灰色透明 linearLayout.setGravity(Gravity.CENTER_HORIZONTAL); linearLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { frameParent.removeView(linearLayout); } }); Rect rect = new Rect(); Point point = new Point(); nearby.getGlobalVisibleRect(rect, point);//获得nearby这个控件的宽高以及XY坐标 nearby这个控件对应就是需要高亮显示的地方 ImageView topGuideview = new ImageView(this); topGuideview.setLayoutParams(new ViewGroup.LayoutParams(rect.width(), rect.height())); topGuideview.setBackgroundResource(R.drawable.iv_topguide); Rect rt = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(rt); topGuideview.setY(point.y - rt.top);//rt.top是手机状态栏的高度 ImageView bottomGuideview = new ImageView(this); bottomGuideview.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); bottomGuideview.setBackgroundResource(R.drawable.iv_bottomguide); bottomGuideview.setY(point.y + topGuideview.getHeight()); linearLayout.addView(topGuideview); linearLayout.addView(bottomGuideview); frameParent.addView(linearLayout); } }
如有不当的地方,还请指正!
相关文章推荐
- Android 新手引导蒙层效果实现代码示例
- Android 新手引导半透明蒙层效果实现
- Android实现自适应正方形GridView(陌陌引导页面效果)
- 新手自定义控件,创建属于自己的下拉刷新(一)---Android,ListView实现IOS的弹性效果
- android实现App新手引导功能
- Android学习——自定义View实现蒙版新手引导
- Android用户首次打开APP出现教学蒙层效果的实现
- Android高级控件(四)——VideoView 实现引导页播放视频欢迎效果,超级简单却十分的炫酷
- Android高级控件(四)——VideoView 实现引导页播放视频欢迎效果,超级简单却十分的炫酷
- Android实战简易教程<四十八>(App引导页面效果实现)
- Android利用ViewPager实现用户引导界面效果的方法
- Android高级控件(四)——VideoView 实现引导页播放视频欢迎效果,超级简单却十分的炫酷
- 一个Android程序中新手引导功能实现方式的变迁
- Android 蒙层效果的实现
- 很赞的引导界面效果Android控件ImageSwitcher实现
- [置顶] Android引导蒙层,安卓新手引导图,引导图层,支持椭圆,圆形,矩形多种形状,一行代码快速搞定
- Android学习——自定义View实现蒙版新手引导(二)
- Android高级控件(四)——VideoView 实现引导页播放视频欢迎效果,超级简单却十分的炫酷
- Android自定义View 实现水波纹动画引导效果
- Android高级控件(四)——VideoView 实现引导页播放视频欢迎效果,超级简单却十分的炫酷