Android怎么实现自定义View展开菜单功能
导读:本文共1303.5字符,通常情况下阅读需要4分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 效果图思路1.下角Button的父View加入一个FrameLayout,也就是图中全屏透明灰色部分。菜单没有弹出的时候设置为不可见。设置FrameLayout点击事件,点击的时候缩回菜单。对应init()2.rameLayout中加入菜单按钮,也就是弹出的那三个。菜单没有弹出的时候设置为不可见。对应addElement()和freshElement()3.右下... ...
目录
(为您整理了一些要点),点击可以直达。效果图
思路
1.下角Button的父View加入一个FrameLayout,也就是图中全屏透明灰色部分。
菜单没有弹出的时候设置为不可见。
设置FrameLayout点击事件,点击的时候缩回菜单。
对应init()
2.rameLayout中加入菜单按钮,也就是弹出的那三个。
菜单没有弹出的时候设置为不可见。
对应addElement()和freshElement()
3.右下角的按钮,旋转图标(也可以不旋转)。
对应setRotateAnimation()
4.性动画将fragment的透明度从0调到1
对应changeBackgroudStatus()
5.单按钮设为可见,并向周围弹出
对应setTranslation()
点我查看源代码
使用方法:
在XML文件中,这个父类是FloatingActionButton:
<com.ice.view.UnfoldButtonandroid: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中:
UnfoldButtonf=(UnfoldButton)findViewById(R.id.unfoldButton);f.addElement(R.drawable.bestjay,newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){//这里写菜单的点击事件}});f.addElement(R.drawable.bestjay,null);//同上f.addElement(R.drawable.bestjay,null);//同上f.setmRotatable(true);//设置图标是否旋转默认为truef.setmScale(1);//设置弹出缩放的比例1为不缩放范围是0—1f.setLength(250);//设置弹出的距离
弹出菜单后,背景颜色由你自己定,你需要在colors.xml里面声明一个color:
<colorname="background">#9b414141</color>
name必须是”background”
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
Android怎么实现自定义View展开菜单功能的详细内容,希望对您有所帮助,信息来源于网络。