gpt4 book ai didi

android - float 操作栏不会为显示 Snackbar 设置动画?

转载 作者:行者123 更新时间:2023-11-30 00:06:53 25 4
gpt4 key购买 nike

在我的 android 应用程序中,我使用了 Clans' 中的 float 操作按钮第 3 方库。喜欢 -

<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_help_outline"
fab:fab_colorNormal="#009688"
fab:fab_label="Learn How-To Use"
fab:fab_size="mini" />

当我的 snackbar 弹出时,clans fab 不像 google 设计库中的默认 float 操作按钮那样动画。

我看到一些混淆规则可以解决这个问题。喜欢:

 -keep class android.support.design.widget.** { *; }
-keep interface android.support.design.widget.** { *; }

我将这些行添加到 proguard-rules.pro 文件中,但没有任何帮助。谁能指出我做错了什么?

任何建议/意见将不胜感激:)

最佳答案

您想到的默认动画由 CoordinatorLayout 提供及其配套的 Behavior 类。

Behaviors may be used to implement a variety of interactions and additional layout modifications ranging from sliding drawers and panels to swipe-dismissable elements and buttons that stick to other elements as they move and animate.

您需要进行两项更改。首先,您应该用 CoordinatorLayout 包装您的 RelativeLayout 并将您的 FloatingActionButton 移出 RelativeLayout 以便它CoordinatorLayout 的直接后代。您的布局应如下所示:

<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">

... your RelativeLayout here

<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:layout_gravity="bottom|end"
app:layout_behavior="com.example.stackoverflow.MyBehavior"/>

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

接下来,您必须创建 MyBehavior 类。我基本上只是采用了设计库的 FloatingActionButton.Behavior 类,并删除了所有并非绝对必要的内容。这是剩下的:

public class MyBehavior extends CoordinatorLayout.Behavior<FloatingActionButton> {

public MyBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public void onAttachedToLayoutParams(CoordinatorLayout.LayoutParams lp) {
if (lp.dodgeInsetEdges == Gravity.NO_GRAVITY) {
lp.dodgeInsetEdges = Gravity.BOTTOM;
}
}

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
return false;
}

@Override
public boolean onLayoutChild(CoordinatorLayout parent, FloatingActionButton child, int layoutDirection) {
parent.onLayoutChild(child, layoutDirection);
return true;
}

@Override
public boolean getInsetDodgeRect(CoordinatorLayout parent, FloatingActionButton child, Rect rect) {
rect.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
return true;
}
}

有了这些,我就得到了你正在寻找的动画:

enter image description here

关于android - float 操作栏不会为显示 Snackbar 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48816162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com