anndroid 模糊引导界面
先上两张图,后面补上代码
我们以前的写法是在需要显示模糊引导的地方,写一个布局,然后第一次使用的时候显示出来。但是这样做代码结构不清晰,所以我们有必要将这些View独立出来,写成一个自定义的View
public class ShowMemberTipsView extends BaseTipsView { @Bind(R.id.btn_sure) Button btnSure; @Bind(R.id.img_close) ImageView imgClose; private static final String UNIQUE_KEY = ShowMemberTipsView.class.getSimpleName(); private Context mContext; public ShowMemberTipsView(Context context) { super(context); this.mContext = context; init(); } public ShowMemberTipsView(Context context, AttributeSet attrs) { super(context, attrs); this.mContext = context; init(); } public ShowMemberTipsView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.mContext = context; init(); } @Override public String getUniquekey() { return UNIQUE_KEY; } private void init() { initLayoutParams(); addStatusBarView(); addContentView(); } private void initLayoutParams() { LayoutParams lp = new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); setOrientation(VERTICAL); setLayoutParams(lp); } private void addContentView() { View view = inflate(mContext, R.layout.view_show_member_tips, null); ButterKnife.bind(this,view); addView(view); } @OnClick(R.id.btn_sure) public void sure() { if (mOnSureListener != null) { mOnSureListener.onSure(ShowMemberTipsView.this); } } @OnClick(R.id.img_close) public void close() { if (mOnCloseListener != null) { mOnCloseListener.onClose(ShowMemberTipsView.this); } } }
引用的布局:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#E6000000"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/topbar_layout_width" android:layout_marginTop="120dp" android:orientation="horizontal"> <RelativeLayout android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:layout_weight="1.0"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/icon_more_mask_btn" /> </RelativeLayout> <View android:layout_width="1.0px" android:layout_height="fill_parent" android:layout_marginBottom="10.0dip" android:layout_marginTop="10.0dip" /> <View android:id="@+id/rl_task_center" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" /> </LinearLayout> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="20dp" android:src="@drawable/icon_more_mask_text" /> <Button android:id="@+id/btn_sure" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="20dp" android:background="@drawable/icon_more_mask_level_btn" /> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> </LinearLayout> <ImageView android:id="@+id/img_close" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginRight="20dp" android:layout_marginTop="20dp" android:padding="5dp" android:src="@drawable/icon_app_upgrade_close" /> </FrameLayout>
最后是一个BaseView,主要是封装一些公共的方法
public abstract class BaseTipsView extends LinearLayout { private static final String TAG = BaseTipsView.class.getSimpleName(); private String mUniqueKey; protected OnCloseListener mOnCloseListener; protected OnSureListener mOnSureListener; public BaseTipsView(Context context) { super(context); init(); } public BaseTipsView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public BaseTipsView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } private void init() { mUniqueKey = getUniquekey(); if (TextUtils.isEmpty(mUniqueKey)) { throw new IllegalArgumentException("Uniquekey must not empty!"); } maskClick(); } //获取状态 protected void addStatusBarView() { View statusBarView = new View(getContext()); statusBarView.setBackgroundColor(getContext().getResources().getColor(R.color.line_color)); int statusBarHeight = getStatusBarHeight(); LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight); statusBarView.setLayoutParams(lp); addView(statusBarView); } public abstract String getUniquekey(); private void maskClick() { this.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 因此View背景透明,防止点击到此View后面的控件 } }); } public void show(final Activity activity) { if (!isMoreTipsShowed()) { addViewToDector(activity); setMoreTipsShowed(true); } } public void dismiss(final Activity activity) { removeViewFromDector(activity); } /** * 添加View到dectorView * @param activity */ private void addViewToDector(final Activity activity) { ViewGroup dectorView = (ViewGroup) activity.getWindow().getDecorView(); dectorView.addView(this); } /** * 从dectorView移出View * @param activity */ private void removeViewFromDector(final Activity activity) { ViewGroup dectorView = (ViewGroup) activity.getWindow().getDecorView(); dectorView.removeView(this); } public void setOnCloseListener(OnCloseListener onCloseListener) { this.mOnCloseListener = onCloseListener; } public void setOnSureListener(OnSureListener onSureListener) { this.mOnSureListener = onSureListener; } public interface OnCloseListener { public void onClose(BaseTipsView baseTipsView); } public interface OnSureListener { public void onSure(BaseTipsView baseTipsView); } protected boolean isMoreTipsShowed() { SharedPreferences sp = getContext().getSharedPreferences(TAG, Context.MODE_PRIVATE); return sp.getBoolean(mUniqueKey, false); } protected void setMoreTipsShowed(boolean isShowed) { SharedPreferences sp = getContext().getSharedPreferences(TAG, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.putBoolean(mUniqueKey, isShowed); editor.commit(); } public int getStatusBarHeight() { int result = 0; int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = getResources().getDimensionPixelSize(resourceId); } return result; } }
最后附上源码下载地址:http://download.csdn.net/detail/xiangzhihong8/9549873
anndroid 模糊引导界面的更多相关文章
- App 引导界面
App 引导界面 1.前言 最近在学习实现App的引导界面,本篇文章对设计流程及需要注意的地方做一个浅显的总结. 附上项目链接,供和我水平类似的初学者参考——http://files.cnblogs. ...
- android——利用SharedPreference做引导界面
很久以前就接触过sharedPreference这个android中的存储介质.但是一直没有实际使用过,今天在看之前做的“民用机型大全”的app时,突然想到可以使用sharedPreference类来 ...
- 【Android UI设计与开发】第05期:引导界面(五)实现应用程序只启动一次引导界面
[Android UI设计与开发]第05期:引导界面(五)实现应用程序只启动一次引导界面 jingqing 发表于 2013-7-11 14:42:02 浏览(229501) 这篇文章算是对整个引导界 ...
- Android UI开发第四十一篇——墨迹天气3.0引导界面及动画实现
周末升级了墨迹天气,看着引导界面做的不错,模仿一下,可能与原作者的代码实现不一样,但是实现的效果还是差不多的.先分享一篇以前的文章,android动画的基础知识,<Android UI开发第十二 ...
- 【Android UI设计与开发】3.引导界面(三)实现应用程序只启动一次引导界面
大部分的引导界面基本上都是千篇一律的,只要熟练掌握了一个,基本上也就没什么好说的了,要想实现应用程序只启动一次引导界面这样的效果,只要使用SharedPreferences类,就会让程序变的非常简单, ...
- 【Android】首次进入应用时加载引导界面
参考文章: [1]http://blog.csdn.net/wsscy2004/article/details/7611529 [2]http://www.androidlearner.net/and ...
- SharedPreference 存储小量数据,一般首次启动显示引导界面就用这个。
写://添加一个SharedPreference并传入数据SharedPreference sharedPreferences = getSharedPreferences("share_d ...
- 转-ViewPager组件(仿微信引导界面)
http://www.cnblogs.com/lichenwei/p/3970053.html 这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager ...
- 【笔记】WPF实现ViewPager引导界面效果及问题汇总
最近在开发项目的首次使用引导界面时,遇到了问题,引导界面类似于安卓手机ViewPager那样的效果,希望通过左右滑动手指来实现切换不同页面,其间伴随动画. 实现思路: 1.界面布局:新建一个UserC ...
随机推荐
- Android简易实战教程--第四十话《Spinner》
对于Spinner控件的介绍和使用方法,可以先看之前写过的一篇博客:Spinner控件详解 本篇就基于这个知识点完成一个简单的小案例: 根据介绍,先写一个布局: <?xml version=&q ...
- Linux内核中的有关Page的算法
static inline int get_order(unsigned long size) { int order; size = (size-1) >> (PAGE_SHIFT-1) ...
- LuaHotUpdate原理
LuaHotUpdate原理(金庆的专栏)项目地址:https://github.com/asqbtcupid/lua_hotupdate只更新函数,不更新数据.主页上有个动画演示.限Windows平 ...
- Unity3d导出场景地图寻路
Unity3d导出场景地图寻路(金庆的专栏)Unity3d中用无渲染的透明盒子摆出地面和阻档区域. this.renderer.enabled = false;所有这些盒子设为Navig ...
- C控制台实现模拟平抛运动算法
平抛运动这个相信读了高中物理都知道这个概念了,详细的我就不说了,不明白的看看百度: 平抛运动 接下来看看用控制台实现的平抛运动算法: #include <stdio.h> #include ...
- 发现----Android Demo
时间悄悄的走,转眼来实习已经三个月了,三个月的时间,小编慢慢的成长着,从刚开始的电商项目到现在的车段子项目,小编在走过一个又一个项目的同时,走过了一个又一个战胜自己的奇迹,每次遇到一个新的技术点,小编 ...
- ubuntu和mac OS X下另一种使用QQ的方法
在ubuntu可以到pidgin官网下载http://www.pidgin.im,然后再安装插件 pidgin-lwqq即可,步骤为: sudo add-apt-repository ppa:lain ...
- 【一天一道LeetCode】#237. Delete Node in a Linked List
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
- Java进阶(四)Java反射TypeToken解决泛型运行时类型擦除问题
在开发时,遇到了下面这条语句,不懂,然习之. private List<MyZhuiHaoDetailModel> listLottery = new ArrayList<MyZhu ...
- Linux中的端口占用问题
本文将会阐述两种解决端口占用的方法. 本文会用到的服务器端的程序如下: #include "unp.h" #include <time.h> int main(int ...