【问题标题】:Android: Animating FAB to top of dialog like SnackBarAndroid:将FAB动画到像SnackBar这样的对话框顶部
【发布时间】:2017-10-03 18:41:12
【问题描述】:

我在 CoordinatorLayout 的底部显示了一个 fab 按钮。在该 FAB 之上,我想显示一个对话框(从底部对其进行动画处理)并将 FAB 动画到同一对话框的顶部,并使其像对话框的关闭按钮一样工作。

我知道如果我们将 CoordinatorLayout 与 FAB 一起使用,SnackBar 的行为具有相同类型的动画,但我也希望对话框进入和退出的动画相同。

有什么方法可以实现同样的动画吗?

【问题讨论】:

    标签: android-animation android-dialog android-coordinatorlayout floating-action-button android-snackbar


    【解决方案1】:

    展示你的小吃店

    public static void showSnackBar(@NonNull View view, @NonNull CharSequence text,
                                        @Snackbar.Duration int duration) {
            Snackbar snack = Snackbar.make(view, text, duration);
            TextView snackTextView = (TextView) snack.getView().findViewById(android.support.design.R.id.snackbar_text);
            snackTextView.setMaxLines(5);
            snack.show();
        }
    

    这里的视图是您对协调器布局的参考

    在你的 xml 中像这样放置你的 fab 按钮

    <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:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
    
    
            <android.support.v4.widget.SwipeRefreshLayout
                android:id="@+id/stream_refresh_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
    
                >
    
                <android.support.v7.widget.RecyclerView
                    android:id="@+id/stream_recyclerview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:focusable="false"
                    android:scrollbars="vertical" />
            </android.support.v4.widget.SwipeRefreshLayout>
    
    
    
    
            <ProgressBar
                android:id="@+id/groupLoadingView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true" />
        </RelativeLayout>
    
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/postButton"
            android:layout_width="58dp"
            android:layout_height="58dp"
            android:layout_marginBottom="16dp"
            android:layout_marginRight="16dp"
            android:scaleType="center"
            android:src="@drawable/chat_newpost_button_selector"
            app:backgroundTint="@color/light_blue_color"
            app:borderWidth="0dp"
            app:elevation="6dp"
            app:layout_anchor="@+id/stream_recyclerview"
            app:layout_anchorGravity="bottom|right|end" />
    
    </android.support.design.widget.CoordinatorLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      • 2015-12-22
      • 2021-10-22
      • 2021-05-25
      • 1970-01-01
      • 2013-04-11
      • 2015-10-18
      相关资源
      最近更新 更多