简体   繁体   English

Android浮动操作按钮选项菜单

[英]Android Floating Action Button options Menu

在此输入图像描述

There are lots of custom libraries for achieving the FAB menu thing. 有很多自定义库可用于实现FAB菜单。 But I want it to be done without using any custom libraries. 但我希望它可以在不使用任何自定义库的情况下完成。 I want to achieve this FAB Menu natively. 我想本地实现这个FAB菜单。

Please don't suggest me any custom library 请不要向我推荐任何自定义库

You can go for android's design library. 你可以去Android的设计库。 add this gradle in to your build file 将此gradle添加到您的构建文件中

compile 'com.android.support:design:23.0.1'

and follow this link, which is a stackoverflow link tells how to use. 并按照链接,这是一个stackoverflow链接告诉如何使用。 and this is the link of an sample app. 这是示例应用程序的链接。

Example : 示例:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:clickable="true"
    android:src="@drawable/ic_done"
    app:layout_anchor="@id/viewA"
    app:layout_anchorGravity="bottom|right|end"/>

you can create multiple fab and play with its visibility 你可以创建多个fab并发挥其可见性

UPDATE UPDATE

I think you have to use third party library to do this. 我认为你必须使用第三方库来做到这一点。 please go through this library, this might help you 请浏览这个图书馆,这可能会对你有帮助

add this dependency to the app build.gradle 将此依赖项添加到app build.gradle

compile 'com.android.support:design:23.1.0' 
 compile 'com.github.clans:fab:1.6.2'

Add follow the below link Floating Action Menu 添加以下链接浮动操作菜单

You could do this natively using visibility... Each press on the FAB (ImageView) will toggle visibility with an animation. 您可以使用可见性本地执行此操作...每次按FAB(ImageView)都会切换动画的可见性。

I won't write a working sample code, but this should be enough info to help implement a custom floating action button in this way. 我不会编写一个可用的示例代码,但这应该足以帮助以这种方式实现自定义浮动操作按钮。

XML XML

android:onClick="fabMainClicked"    

JAVA JAVA

public void fabMainClicked(View view) 
{
    ImageView fabDrop1 = (ImageView) findViewById(R.id.fabDrop1);
    ImageView fabDrop2 = (ImageView) findViewById(R.id.fabDrop2);
    if (fabDrop1.getVisibility() == fabDrop1.GONE)
    {
        fabDrop1.setVisibility(fabDrop1.VISIBLE);
        fabDrop2.setVisibility(fabDrop2.VISIBLE);
    }
}  

Each ImageView will need to be animated via a custom animator to slide up or onto the screen. 每个ImageView都需要通过自定义动画制作动画,以向上或向上滑动到屏幕上。

Each ImageView will use a res/drawable as the background to provide a circle and a res/drawable for the center image. 每个ImageView将使用res / drawable作为背景,为中心图像提供圆和res / drawable。

Scale type should be set to center. 比例类型应设置为居中。

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM