gpt4 book ai didi

android - 使用 BottomAppBar Material 设计组件的 fragment 过渡

转载 作者:行者123 更新时间:2023-12-04 09:24:17 24 4
gpt4 key购买 nike

我正在尝试实现 Material 设计组件文档中针对 float 操作按钮指定的以下底部 appbar 转换。

enter image description here

此行为的官方设计文档指定为 here

现在,此 View 的实现文档指定以下内容:

FloatingActionButton Alignment Modes The FloatingActionButton can be aligned either to the center (FAB_ALIGNMENT_MODE_CENTER) or to the end (FAB_ALIGNMENT_MODE_END) by calling setFabAlignmentMode(int). The default animation will automatically be run. This can be coordinated with a Fragment transition to allow for a smooth animation from a primary screen to a secondary screen. (source)



我似乎找不到任何地方实现的行为示例。
我用于底部 appbar 组件的代码如下(在我的 Activity 布局文件中):
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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=".main.MainActivity">

<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:background="#000">

</LinearLayout>

<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_app_bar"
style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fabAlignmentMode="center"
app:hideOnScroll="true"
app:navigationIcon="@drawable/ic_hamburger_menu" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/bottom_app_bar"
app:srcCompat="@drawable/ic_add" />


</androidx.coordinatorlayout.widget.CoordinatorLayout>

非常感谢有关该问题的一些指导或示例。

谢谢!

最佳答案

您只需隐藏它,然后监听器检测到它的隐藏并再次显示它,转换会自动执行。您还必须同时切换 fragment 。

binding.fabMain.hide(new FloatingActionButton.OnVisibilityChangedListener() {
@Override
public void onShown(FloatingActionButton fab) {
super.onShown(fab);
}

@Override
public void onHidden(FloatingActionButton fab) {
super.onHidden(fab);
binding.fabMain.show();
}
});

关于android - 使用 BottomAppBar Material 设计组件的 fragment 过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52045661/

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