Android编程实现仿QQ发表说说,上传照片及弹出框效果【附demo源码下载】
程序员文章站
2023-12-22 20:18:22
本文实例讲述了android编程实现仿qq发表说说,上传照片及弹出框效果。分享给大家供大家参考,具体如下:
代码很简单,主要就是几个动画而已,图标什么的就随便找了几个,效...
本文实例讲述了android编程实现仿qq发表说说,上传照片及弹出框效果。分享给大家供大家参考,具体如下:
代码很简单,主要就是几个动画而已,图标什么的就随便找了几个,效果图:
动画说明:
1.点击右上角按钮,菜单从顶部下拉弹出,同时背景变暗;
2.再次点击右上角按钮,点击返回键,或者点击空白区域(也就是变暗的部分),菜单向上收回;
3.点击菜单上的按钮响应事件,同时菜单收回(效果同2)
重要说明:动画结束后必须clearanimation,否则隐藏状态的view依然能响应点击事件
主体代码:
public class mainactivity extends activity { //添加数据按钮 private imageview adddataiv; //下拉功能菜单 private linearlayout dropdownview; private view bgview; //当前下拉菜单是否为显示状态 private boolean showitems = false; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); adddataiv = (imageview) findviewbyid(r.id.main_newdata); dropdownview = (linearlayout) findviewbyid(r.id.dropdownview); bgview = findviewbyid(r.id.main_bg); adddataiv.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (!showitems) { showview(); } else { dismissview(); } } }); //点击空白隐藏弹出框 bgview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (showitems) { dismissview(); } } }); //下拉功能菜单上按钮的点击事件 view.onclicklistener l = new onclickimpl(); findviewbyid(r.id.dropdown_item1).setonclicklistener(l); findviewbyid(r.id.dropdown_item2).setonclicklistener(l); findviewbyid(r.id.dropdown_item3).setonclicklistener(l); findviewbyid(r.id.dropdown_item4).setonclicklistener(l); } //显示下拉菜单 private void showview() { showitems = true; adddataiv.startanimation(animationutils.loadanimation(mainactivity.this, r.anim.rotate_open)); dropdownview.startanimation(animationutils.loadanimation(this, r.anim.drop_down)); dropdownview.setvisibility(view.visible); bgview.startanimation(animationutils.loadanimation(mainactivity.this, r.anim.fade_dark)); bgview.setvisibility(view.visible); } //隐藏下拉菜单 private void dismissview() { showitems = false; adddataiv.startanimation(animationutils.loadanimation(mainactivity.this, r.anim.rotate_close)); animation dropupanim = animationutils.loadanimation(this, r.anim.drop_up); dropupanim.setanimationlistener(new animlistenerimpl(dropdownview)); dropdownview.startanimation(dropupanim); dropdownview.setvisibility(view.invisible); animation fadelightanim = animationutils.loadanimation(mainactivity.this, r.anim.fade_light); fadelightanim.setanimationlistener(new animlistenerimpl(bgview)); bgview.startanimation(fadelightanim); bgview.setvisibility(view.invisible); } //点击返回键时,如果下拉菜单是显示状态,则隐藏它 @override public void onbackpressed() { if (showitems) { dismissview(); return; } super.onbackpressed(); } private class onclickimpl implements view.onclicklistener { @override public void onclick(view v) { if (!showitems) { return; } int id = v.getid(); switch (id) { case r.id.dropdown_item1: toast.maketext(mainactivity.this, "item1 onclick", toast.length_short).show(); dismissview(); break; case r.id.dropdown_item2: toast.maketext(mainactivity.this, "item2 onclick", toast.length_short).show(); dismissview(); break; case r.id.dropdown_item3: toast.maketext(mainactivity.this, "item3 onclick", toast.length_short).show(); dismissview(); break; case r.id.dropdown_item4: toast.maketext(mainactivity.this, "item4 onclick", toast.length_short).show(); dismissview(); break; default: break; } } } //动画结束后必须clearanimation,否则隐藏状态的view依然能响应点击事件 private class animlistenerimpl implements animation.animationlistener { private view view; public animlistenerimpl(view view) { this.view = view; } @override public void onanimationstart(animation animation) { } @override public void onanimationend(animation animation) { view.clearanimation(); } @override public void onanimationrepeat(animation animation) { } } }
完整实例代码点击此处本站下载。
更多关于android相关内容感兴趣的读者可查看本站专题:《android开发动画技巧汇总》、《android编程之activity操作技巧总结》、《android视图view技巧总结》、《android布局layout技巧总结》、《android开发入门与进阶教程》、《android资源操作技巧汇总》及《android控件用法总结》
希望本文所述对大家android程序设计有所帮助。