Android 带有浮动操作按钮的循环进度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25902713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:48:27  来源:igfitidea点击:

Circular Progress with a floating action button

androidandroid-5.0-lollipopmaterial-designfloating-action-button

提问by Marco Souza

I`m studing the new material design and I'm having some problems.

我正在研究新材料设计,但遇到了一些问题。

I would like to know if some of you know how can I do a progress bar with the floating action button like this https://dribbble.com/shots/1644982-Animated-circle-loader-FAB-with-integration-gif

我想知道你们中的一些人是否知道如何使用像这样的浮动操作按钮来制作进度条 https://dribbble.com/shots/1644982-Animated-circle-loader-FAB-with-integration-gif

Is there any api on Android L for this?

Android L 上是否有任何 api 用于此?

Thanks

谢谢

采纳答案by Marco Souza

I found a lib which does that, it seems pretty simple

我找到了一个可以做到这一点的库,它看起来很简单

https://github.com/ckurtm/FabButton

https://github.com/ckurtm/FabButton

回答by kunmi

This worked for me, I used a Relative-layout and fitted both in the center of the Relative-Layout.

这对我有用,我使用了相对布局并将两者都安装在相对布局的中心。

...
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_margin="16dp"
    app:layout_anchor="@id/my_recycler_view"
    app:layout_anchorGravity="bottom|right|end"
    >

    <ProgressBar
        android:id="@+id/fabProgress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:indeterminateTint="@color/colorPrimary"
        />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/newReportButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_dialog_email"
        app:fabSize="normal"
        android:layout_centerInParent="true"
        />

</RelativeLayout>
...

回答by Dmitry

You can use it:https://github.com/DmitryMalkovich/circular-with-floating-action-buttonto integrate circular progress with floating action button. The solution is not a custom fab, it is only a simple container for your our fab, so you can style as before!

您可以使用它:https : //github.com/DmitryMalkovich/circular-with-floating-action-button将循环进度与浮动操作按钮集成。解决方案不是定制晶圆厂,它只是我们晶圆厂的一个简单容器,因此您可以像以前一样设计风格!

<com.dmitrymalkovich.android.ProgressFloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:clickable="true">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_backup_black_24dp" />

    <ProgressBar
        style="@style/Widget.AppCompat.ProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</com.dmitrymalkovich.android.ProgressFloatingActionButton>

回答by Zon

I would suggest Floating Action Button by Jorge Costillo. It is better than Kurt's one from the accepted answer which I have also tried.

我会建议Jorge Costillo 的 Floating Action Button。它比我也尝试过的已接受答案中的 Kurt 更好。

The Kurt's one has no support for vector drawables (srcCompat attribute), image sizing problems, no fab-mini support, material icon guideline mismathces.

Kurt 的一个不支持矢量可绘制对象(srcCompat 属性),图像大小问题,没有 fab-mini 支持,材质图标指南错误。

Costillo's FAB is also more like a wrapper around standard Android FAB.

Costillo 的 FAB 也更像是标准 Android FAB 的包装器。

回答by Jose Luis Larraz

I have solved the issue adding a progess bar to the layout and then using a custom behaviour for the progress bar. Layout:

我已经解决了在布局中添加进度条,然后为进度条使用自定义行为的问题。布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="es.mediaserver.newinterfacedlna.MainActivity">

    <android.support.design.widget.AppBarLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main"
        android:id="@+id/include" />

    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:layout_margin="28dp"
        android:layout_gravity="bottom|center"
        app:srcCompat="@android:drawable/ic_media_play" />

    <ProgressBar
        android:id="@+id/progressBar2"
        style="?android:attr/progressBarStyle"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_gravity="bottom|center"
        android:indeterminate="true"
        android:layout_margin="@dimen/fab_margin"
        />

</android.support.design.widget.CoordinatorLayout>

Custom Behaviour component

自定义行为组件

    public static class SnackBarBehavior extends CoordinatorLayout.Behavior<View> {
    private static final boolean SNACKBAR_BEHAVIOR_ENABLED;
    public SnackBarBehavior() {
        super();
    }
    public SnackBarBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
        return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
        child.setTranslationY(translationY);
        return true;
    }

    @Override
    public void onDependentViewRemoved(CoordinatorLayout parent, View child, View dependency) {
        child.setTranslationY(0);
    }

    static {
        SNACKBAR_BEHAVIOR_ENABLED = Build.VERSION.SDK_INT >= 11;
    }
}

And finally in the onCreate (or in the layout with app:layout_behavior="xxx.xxx.SnackBarBehavior")

最后在 onCreate (或在 app:layout_behavior="xxx.xxx.SnackBarBehavior" 的布局中)

ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar2);
SnackBarBehavior snackBarBehavior = new SnackBarBehavior();
        CoordinatorLayout.LayoutParams coordinatorParams = (CoordinatorLayout.LayoutParams) progressBar.getLayoutParams();
        coordinatorParams.setBehavior(snackBarBehavior);

Note: I based my behaviour component in the one posted here How to move a view above Snackbar just like FloatingButton

注意:我的行为组件基于此处发布的 如何像 FloatingButton 一样在 Snackbar 上方移动视图

回答by Andy B

You could use the following library to achieve the material style button > https://github.com/makovkastar/FloatingActionButton(or this one > https://github.com/futuresimple/android-floating-action-button)

您可以使用以下库来实现材质样式按钮 > https://github.com/makovkastar/FloatingActionButton(或这个 > https://github.com/futuresimple/android-floating-action-button

For the spinner you could also use this library > https://github.com/oguzbilgener/CircularFloatingActionMenu

对于微调器,您还可以使用此库> https://github.com/oguzbilgener/CircularFloatingActionMenu

You could then combine these two components by adding them to a RelativeLayout (one on top of the other) and also add some animations i.e. Expand button with zoom, expand progress behind with zoom. All you'd need to do then is hook into the progress bar code to contract it once it had completed its loading i.e. shrink it behind the button.

然后,您可以通过将这两个组件添加到一个相对布局(一个在另一个之上)来组合这两个组件,并添加一些动画,即带缩放的展开按钮,用缩放在后面展开进度。然后您需要做的就是在进度条代码完成加载后对其进行收缩,即将其缩小到按钮后面。

For backwards compatible animation have a look at 9 old Androids here > http://nineoldandroids.com/

对于向后兼容的动画,请在此处查看 9 个旧的 Android > http://nineoldandroids.com/

Hope this helps.

希望这可以帮助。