NiftyDialogEffects(各种动画的dialog)
来源:互联网 发布:qs网络语是什么意思 编辑:程序博客网 时间:2024/05/16 08:03
NiftyDialogBuilder:
该类继承Dialog,提供了快速创建dialog的方法
在构造器中就将dialog的view进行了初始化:
public NiftyDialogBuilder(Context context) {super(context);init(context);}public NiftyDialogBuilder(Context context, int theme) {super(context, theme);init(context);}
private void init(Context context) {mDialogView = View.inflate(context, R.layout.dialog_layout, null);mLinearLayoutView = (LinearLayout) mDialogView.findViewById(R.id.parentPanel);mRelativeLayoutView = (RelativeLayout) mDialogView.findViewById(R.id.main);mLinearLayoutTopView = (LinearLayout) mDialogView.findViewById(R.id.topPanel);mLinearLayoutMsgView = (LinearLayout) mDialogView.findViewById(R.id.contentPanel);mFrameLayoutCustomView = (FrameLayout) mDialogView.findViewById(R.id.customPanel);mTitle = (TextView) mDialogView.findViewById(R.id.alertTitle);mMessage = (TextView) mDialogView.findViewById(R.id.message);mIcon = (ImageView) mDialogView.findViewById(R.id.icon);mDivider = mDialogView.findViewById(R.id.titleDivider);mButton1 = (Button) mDialogView.findViewById(R.id.button1);mButton2 = (Button) mDialogView.findViewById(R.id.button2);setContentView(mDialogView);this.setOnShowListener(new OnShowListener() {@Overridepublic void onShow(DialogInterface dialogInterface) {mLinearLayoutView.setVisibility(View.VISIBLE);if (type == null) {type = Effectstype.Slidetop;}start(type);}});mRelativeLayoutView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {if (isCancelable)dismiss();}});}并且在show的监听器里面设置了动画的开始:
private void start(Effectstype type) {BaseEffects animator = type.getAnimator();if (mDuration != -1) {animator.setDuration(Math.abs(mDuration));}animator.start(mRelativeLayoutView);}这个方法可以通过枚举类来获得对应动画类的响应实例,然后设置动画时间,以及用animator.start(mRelativeLayoutView);开启动画:
public void start(View view) { reset(view); setupAnimation(view); mAnimatorSet.start(); } public void reset(View view) { ViewHelper.setPivotX(view, view.getMeasuredWidth() / 2.0f); ViewHelper.setPivotY(view, view.getMeasuredHeight() / 2.0f); }首先通过setupAnimation(view);来安装动画:
@Override protected void setupAnimation(View view) { getAnimatorSet().playTogether( ObjectAnimator.ofFloat(view,"alpha",0,1).setDuration(mDuration) ); }
安装动画是通过调用BaseEffects里面的mAnimatorSet来将不同的属性动画放在一起。
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);WindowManager.LayoutParams params = getWindow().getAttributes();params.height = ViewGroup.LayoutParams.MATCH_PARENT;params.width = ViewGroup.LayoutParams.MATCH_PARENT;getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);}这样以后在调用这个dialog.show()的时候就不会重复初始化。
把这个dialog设计成单例模式,可以防止被实例化多次而占用了更大的内存,这种单例模式是双重检查加锁的单例:
public static NiftyDialogBuilder getInstance(Context context) {if (instance == null || !tmpContext.equals(context)) {synchronized (NiftyDialogBuilder.class) {if (instance == null || !tmpContext.equals(context)) {instance = new NiftyDialogBuilder(context, R.style.dialog_untran);}}}tmpContext = context;return instance;}比如loading的对话框这种全局使用的对话框适合做单例模式
0 0
- NiftyDialogEffects(各种动画的dialog)
- 漂亮动画效果的Dialog--NiftyDialogEffects
- NiftyDialogEffects:集成了多种动画效果的Dialog控件
- 关于NiftyDialogEffects Dialog弹出动画第二次进入弹出dialog闪退Bug
- 绚丽多彩的对话框NiftyDialogEffects(多种颜色和动画进入效果)
- 各种自定义的dialog
- Android的各种Dialog
- 各种Dialog的使用
- Android Dialog库内置Dialog以及各种动画.支持自定义Dialog和动画
- 初学者---Android 一款好用的Dialog开源框架NiftyDialogEffects
- 自定义dialog和弹出dialog的动画
- 10.自定义Dialog--dialog的动画
- Dialog的各种使用方式
- 各种dialog的封装实现
- 各种dialog的封装实现
- 各种Dialog,满足你的各种需求
- 各种Dialog,满足你的各种需求
- 嗯~有意思的Dialog动画
- 面试题
- 哲学家就餐-条件变量
- Uva-815 - Flooded!-AC
- 解决Magento1.9 安装后前台首页的链接必须加上index.php才能访问
- Java - Error: Attribute value must be constant
- NiftyDialogEffects(各种动画的dialog)
- Android NDK开发篇(一):新版NDK环境搭建(免Cygwin,超级快)
- OPENWRT设置之命令行下简单配置有线和无线
- Android使用NDK调用C语言写的SO进行加密
- hdu 5171 GTY's birthday gift (BestCoder Round #29)
- tibco学习资源
- linux 下文件I/O编程 (open、read、write、lseek、close)
- uva 10169
- 4.2 可视化管线