简体   繁体   English

如何创建浮动操作按钮?

[英]How is floating action button created?

While using the floating action button provided by android developer, I can't help but to wonder how exactly did they even achieve the floating action button from scratch. 在使用android开发人员提供的浮动操作按钮时,我不禁想知道他们到底是如何从头实现浮动操作按钮的。

1) I would like to know how exactly was the floating action button was built 1)我想知道浮动操作按钮是如何制作的

2) how is the android able to animate only the plus to become something else? 2)android如何仅使加号动画以成为其他东西?

This might be a repeat of other post but I have checked already and can't seem to find any post asking this same question. 这可能是其他帖子的重复,但我已经检查过了,似乎找不到任何问这个问题的帖子。 If you find one that ask similar question then please let me know. 如果您发现有人提出类似问题,请告诉我。

My post is different from this post: How can I add the new "Floating Action Button" between two widgets/layouts because the post above only explain how to use the android FAB library and does not explain how FAB are created from scratch. 我的帖子与此帖子不同: 我如何在两个小部件/布局之间添加新的“浮动操作按钮”,因为上面的帖子仅说明了如何使用android FAB库,而没有说明如何从头开始创建FAB。

FloatingActionButton class mainly extends the VisibilityAwareImageButton which extends the imagebutton . FloatingActionButton类主要扩展了VisibilityAwareImageButton ,后者扩展了imagebutton So, from scratch when you start you should start from extending imagebutton. 因此,从头开始时,您应该从扩展imagebutton开始。 Then when you get VisibilityAwareImageButton you can create your FloatingButton class. 然后,当您获得VisibilityAwareImageButton ,可以创建FloatingButton类。 Code for VisibilityAwareImageButton is given below 下面给出了VisibilityAwareImageButton代码

package android.support.design.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageButton;

class VisibilityAwareImageButton extends ImageButton {

private int mUserSetVisibility;

public VisibilityAwareImageButton(Context context) {
    this(context, null);
}

public VisibilityAwareImageButton(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
}

public VisibilityAwareImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mUserSetVisibility = getVisibility();
}

@Override
public void setVisibility(int visibility) {
    internalSetVisibility(visibility, true);
}

final void internalSetVisibility(int visibility, boolean fromUser) {
    super.setVisibility(visibility);
    if (fromUser) {
        mUserSetVisibility = visibility;
    }
}

final int getUserSetVisibility() {
    return mUserSetVisibility;
}
} 

How they created the Floating button: 他们如何创建浮动按钮:

well the source code is available in below link from google 以及源代码可从下面的谷歌链接获得

https://android.googlesource.com/platform/frameworks/support/+/master/design/src/android/support/design/widget/FloatingActionButton.java?autodive=0%2F%2F https://android.googlesource.com/platform/frameworks/support/+/master/design/src/android/support/design/widget/FloatingActionButton.java?autodive=0%2F%2F

And the VisibilityAwareImageButton code is taken from below link https://github.com/android/platform_frameworks_support/blob/master/design/base/android/support/design/widget/VisibilityAwareImageButton.java 并且VisibilityAwareImageButton代码是从下面的链接https://github.com/android/platform_frameworks_support/blob/master/design/base/android/support/design/widget/VisibilityAwareImageButton.java获取的

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

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