Android 仿微信右上角点击加号弹出菜单
今天在做仿微信点击右上角加号弹出菜单出现了一点问题,故记录下来 需要也能对你有用
先来看效果图:
欧克,上面的实现效果主要时使用PopupWindow实现的,其中有趣的知识点是1.点击加号按钮弹出菜单,整体颜色变灰,2.再次点击加号按钮,收起菜单,3.开启菜单时点击外部实现收起菜单
好了,废话不多说让我们来看代码
首先,声明一个类继承自PopupWindow (这里你也可以在使用的activity/Fragment中使用new PopupWindow方式来实现)
public class DevicePopWindow extends PopupWindow {public DevicePopWindow(){super(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);//这里要注意设置setOutsideTouchable之前要设置 setBackgroundDrawable()//否则点击外部无法关闭popsetBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));setOutsideTouchable(true);//获取焦点设置为true 这样再次点击菜单时 就隐藏菜单setFocusable(true);View inflate = LayoutInflater.from(BaseApplication.getAppContext()).inflate(R.layout.pop_window_device, null);setContentView(inflate);//设置窗口进入和退出的动画setAnimationStyle(R.style.pop_add);}
}
R.layout.pop_window_device.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:padding="10dp"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginEnd="8dp"android:background="@drawable/shape_device_pop"android:orientation="vertical"android:paddingBottom="20dp"android:paddingEnd="16dp"android:paddingStart="26dp"android:paddingTop="20dp"><TextViewandroid:id="@+id/tv_1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:text="发起群聊"android:textColor="@color/colorBlack"android:textSize="16sp"/><TextViewandroid:id="@+id/tv_2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:text="添加朋友"android:textColor="@color/colorBlack"android:textSize="16sp"/><TextViewandroid:id="@+id/tv_3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:text="扫一扫"android:textColor="@color/colorBlack"android:textSize="16sp"/><TextViewandroid:id="@+id/tv_4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:text="收付款"android:textColor="@color/colorBlack"android:textSize="16sp"/><TextViewandroid:id="@+id/tv_5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:text="帮助与反馈"android:textColor="@color/colorBlack"android:textSize="16sp"/></LinearLayout></LinearLayout>
R.style.pop_add 样式
<style name="pop_add" parent="android:Animation"><item name="android:windowEnterAnimation">@anim/pop_add_show</item><item name="android:windowExitAnimation">@anim/pop_add_hide</item>
</style>
@anim/pop_add_show.xml pop弹出动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"><alphaandroid:duration="300"android:fromAlpha="0.0"android:toAlpha="1.0"/><scaleandroid:duration="300"android:fromXScale="0"android:fromYScale="0"android:interpolator="@android:anim/decelerate_interpolator"android:pivotX="85%"android:pivotY="0%"android:toXScale="1.0"android:toYScale="1.0"/></set>
@anim/pop_add_hide.xml pop隐藏动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alphaandroid:duration="300"android:fromAlpha="1.0"android:toAlpha="0.0"/>
<scaleandroid:duration="300"android:fromXScale="1.0"android:fromYScale="1.0"android:interpolator="@android:anim/accelerate_interpolator"android:pivotX="85%"android:pivotY="0%"android:toXScale="0"android:toYScale="0"/>
</set>
在我们的页面中进行使用
class DeviceFragment : Fragment() {lateinit var devicePopWindow: DevicePopWindowlateinit var rootView: Viewlateinit var successView:Viewoverride fun onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState): View {rootView = inflater.inflate(R.layout.base_device_fragment_layout,container,false)initView(inflater)initListener()return rootView}fun initView(inflate: View) {devicePopWindow = DevicePopWindow()}fun initListener() {rootView.findViewById<ImageView>(R.id.device_head_add).setOnClickListener {//设置pop显示位置devicePopWindow.showAsDropDown(it,-150,10)backgroundAlpha(0.8f)}//pop消失的监听devicePopWindow.setOnDismissListener {backgroundAlpha(1.0f)}}/*** 此方法用于改变背景的透明度,从而达到“变暗”的效果*/private fun backgroundAlpha(bgAlpha: Float) {val lp: WindowManager.LayoutParams = activity!!.window.attributes// 0.0-1.0lp.alpha = bgAlphaactivity!!.window.attributes = lp// everything behind this window will be dimmed.// 此方法用来设置浮动层,防止部分手机变暗无效activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)}
}
欧克。到这里就结束了,东西都挺简单的 详细的注释也在代码里 就不再累赘了
Android 仿微信右上角点击加号弹出菜单相关推荐
- Android自定义弹窗模仿微信,Android仿微信右上角点击加号弹出PopupWindow
本文实例为大家分享了Android仿微信右上角点击加号弹出展示的具体代码,供大家参考,具体内容如下 一.要弹出的布局,随便设计 android:layout_width="match_par ...
- 仿微信右上角点击加号弹出PopupWindow
一.要弹出的布局,随便设计 <LinearLayout android:layout_width="match_parent" android:layout_height=& ...
- Android仿Qzone底部导航栏加号弹出菜单
最近看到QQ空间 新浪微博-.好多应用底部导航栏都有加号点击弹出菜单,于是就写了一个demo,来给没做过这个功能的小伙伴一个参考,希望对大家有所帮助,demo中的图片均来源于Qzone 仅作为学习交流 ...
- android qq右上加号,仿QQ空间点击加号弹出菜单特效
最近项目需要,前几天写了一个仿微信相册(包括编辑相册)功能,审核代码的时候发现同事要实现一个类似仿QQ空间点击加号弹出菜单特效,于是看了一些他的代码,我发现虽然他实现了功能,但是不够完善,所以我又花了 ...
- android点击加号,Android仿微信朋友圈点击加号添加图片功能
本文为大家分享了类似微信朋友圈,点击+号图片,可以加图片功能,供大家参考,具体内容如下 xml: xmlns:app="http://schemas.android.com/apk/res- ...
- android 微信评论功能,Android仿微信朋友圈点击评论自动定位到相关行功能
最近闲来无事,随便看看各种UI实现的代码 打开你的微信朋友圈,点击评论,你就会发现有一个小细节:文本输入框的高度恰好定位到这条信息的底部位置 这个实现起来其实很简单,咱们就来看看吧 最简单的Recyc ...
- android 点击图片动画效果,Android仿微信图片点击全屏效果
废话不多说,先看下Android图片点击全屏效果: 先是微信的 再是模仿的 先说下实现原理,再一步步分析 这里总共有2个Activity一个就是主页,一个就是显示我们图片效果的页面,参数通过Inten ...
- android 查找朋友圈,Android仿微信朋友圈点击评论自动定位到相关行功能
最近闲来无事,随便看看各种UI实现的代码 打开你的微信朋友圈,点击评论,你就会发现有一个小细节:文本输入框的高度恰好定位到这条信息的底部位置 这个实现起来其实很简单,咱们就来看看吧 最简单的Recyc ...
- android 微信评论功能,Android仿微信朋友圈点击评论自动定位到相关行功能.pdf
Android仿仿微微信信朋朋友友圈圈点点击击评评论论自自动动定定位位到到相相关关行行功功能能 这篇文章主要介绍了android仿微信朋友圈点击评论自动定位到相关行功能的实现,本文图文并茂给大家介绍的 ...
最新文章
- svn中的ignore
- 今年1篇Science,2篇NBT,2篇MP,1篇PNAS等11篇文章,遗传发育所白洋组在植物微生物组取得系列进展!
- Android一键多渠道分发打包实战和解析
- XCTF-Reverse:simple-unpack
- XMLHTTP.readyState的五种状态
- 初识C++之指针与引用
- BZOJ.2555.SubString(后缀自动机 LCT)
- 中国晶圆和集成电路(IC)行业市场供需与战略研究报告
- 玩转VIM编辑器-自动补全
- 洛谷——P1851 好朋友
- 专业的PRD撰写模板
- Docker——网络
- [移动GIS] 4.1-TDOA定位
- 006-基于hyperledger fabric1.4( 官方文档)编写第一个应用【外部nodejs调用】
- 查看英伟达Nvidia显卡、cuda版本
- linux分区写保护,mtd分区写保护关闭
- Latex从.dtx文件分解得到.sty文件
- arduino烧写报错:can‘t open device “\\.\COM1“
- it巨头的组织架构图
- 计算机毕业设计Java学生考勤管理系统(源码+系统+mysql数据库+lw文档
热门文章
- 分布式架构-Redis 从入门到精通 完整案例 附源码
- php表单多选内容取出,php处理单名多值表单的方法(多选下拉框)
- python读啥-python怎么读,python是什么意思
- matlab simulink 气动伺服系统分析与控制
- 说到产品需求,到底谁的是第一优先级?
- 奔驰s如何升级鸿蒙,如何将一辆奔驰S级变成迈巴赫S级?只需要这几步,4s店都看不出来...
- java wav文件转换为mp3
- Android项目——短信发送器
- vue学习十八(axios)
- asp.net客户积分兑换管理系统VS开发sqlserver数据库web结构c#编程计算机网页源码项目