Android自定义View展开菜单功能的实现
作者:狗大 时间:2022-02-08 06:28:49
先给大家展示下效果图,如果大家感觉不错,请参考实现代码。
思路
1.下角Button的父View加入一个FrameLayout,也就是图中全屏透明灰色部分。
菜单没有弹出的时候设置为不可见。
设置FrameLayout点击事件,点击的时候缩回菜单。
对应init()
2.rameLayout中加入菜单按钮,也就是弹出的那三个。
菜单没有弹出的时候设置为不可见。
对应addElement()和freshElement()
3.右下角的按钮,旋转图标(也可以不旋转)。
对应setRotateAnimation()
4.性动画将fragment的透明度从0调到1
对应changeBackgroudStatus()
5.单按钮设为可见,并向周围弹出
对应setTranslation()
点我查看源代码
使用方法:
在XML文件中,这个父类是FloatingActionButton:
<com.ice.view.UnfoldButton
android:id="@+id/unfoldButton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginBottom="18dp"
app:elevation="5dp"
app:borderWidth="0dp"
android:layout_gravity="right"
android:src="@drawable/add"
android:background="@color/colorAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true" />
在Activity中:
UnfoldButton f = (UnfoldButton) findViewById(R.id.unfoldButton);
f.addElement(R.drawable.bestjay, new View.OnClickListener() {
@Override
public void onClick(View v) {
//这里写菜单的点击事件
}
});
f.addElement(R.drawable.bestjay,null);//同上
f.addElement(R.drawable.bestjay,null);//同上
f.setmRotatable(true);//设置图标是否旋转 默认为true
f.setmScale(1);//设置弹出缩放的比例 1为不缩放 范围是0—1
f.setLength(250);//设置弹出的距离
弹出菜单后,背景颜色由你自己定,你需要在colors.xml里面声明一个color:
<color name="background">#9b414141</color>
name必须是”background”
以上所述是小编给大家介绍的Android自定义View展开菜单功能的实现网站的支持!
来源:http://blog.csdn.net/q1242027878/article/details/73832036
标签:android,view,菜单
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringCloud实战小贴士之Zuul的路径匹配
2021-05-26 13:26:36
jmeter+ant+jenkins自动化测试环境配置搭建过程
2023-11-17 23:38:06
![](https://img.aspxhome.com/file/2023/4/81184_0s.png)
SpringBoot登录验证码实现过程详解
2023-04-26 12:24:05
![](https://img.aspxhome.com/file/2023/1/64941_0s.png)
IDEA中配置文件模板的添加方法
2023-10-28 17:52:31
![](https://img.aspxhome.com/file/2023/4/58674_0s.jpg)
list集合去除重复对象的实现
2022-10-16 23:02:42
Android系统制作自定义签名的例子
2023-02-02 05:10:04
![](https://img.aspxhome.com/file/2023/5/94985_0s.jpg)
java中staticclass静态类详解
2021-10-12 19:47:35
详解SpringCloud的负载均衡
2022-03-14 03:42:28
![](https://img.aspxhome.com/file/2023/8/78348_0s.png)
java生成饼图svg及JFreeChart生成svg图表
2023-10-25 19:27:00
基于StreamRead和StreamWriter的使用(实例讲解)
2022-09-11 22:12:36
java解析json数组方式
2023-08-10 17:22:14
![](https://img.aspxhome.com/file/2023/8/58188_0s.png)
Java基于JDK 1.8的LinkedList源码详析
2021-07-15 03:29:26
![](https://img.aspxhome.com/file/2023/9/68159_0s.png)
Idea防沉迷插件StopCoding的安装使用教程
2023-11-23 07:29:32
![](https://img.aspxhome.com/file/2023/6/59696_0s.png)
Java中instanceof关键字实例讲解
2023-08-04 07:48:31
![](https://img.aspxhome.com/file/2023/5/63305_0s.png)
JDBC增删改查和查唯一的完整代码解析
2023-12-22 15:53:30
C# List引用类型克隆的3种方法
2023-04-19 14:20:44
![](https://img.aspxhome.com/file/2023/6/98286_0s.png)
java判断中文字符串长度的简单实例
2022-12-19 09:00:26
基于spring boot 的配置参考大全(推荐)
2021-11-28 23:32:41
C#值类型、引用类型、泛型、集合、调用函数的表达式树实践
2022-03-09 20:55:27
C#编程自学之开篇介绍
2023-12-16 07:58:55
![](https://img.aspxhome.com/file/2023/0/116440_0s.png)