gpt4 book ai didi

java - CollapsingToolbarLayout 和 FloatingActionButton

转载 作者:行者123 更新时间:2023-12-05 00:01:19 27 4
gpt4 key购买 nike

我有 CollapsingToolbarLayout 和两个 FloatingActionButtons。这些 FAB 仅在 Toolbar 展开时可见。折叠时,它们会隐藏起来。如果工具栏也折叠了,我需要它们可见。我该怎么做?

非常感谢您的提示...

    <?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"
android:fitsSystemWindows="true"
tools:context=".CalendarEventInsUpdActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

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

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

<include layout="@layout/content_calendar_event"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_save"
app:backgroundTint="@android:color/holo_green_light"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|center"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_revert"
app:backgroundTint="@android:color/holo_red_light"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"/>

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

最佳答案

您需要添加一个 Behavior到 FAB。

尝试类似的东西:

public class ScrollingFABBehavior extends CoordinatorLayout.Behavior<FloatingActionButton> {
private int toolbarHeight;

public ScrollingFABBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
this.toolbarHeight = Utils.getToolbarHeight(context);
}

@Override
public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton fab, View dependency) {
return dependency instanceof AppBarLayout;
}

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton fab, View dependency) {
//do nothing with the fab or write your logic for the FAB
return true;
}
}

然后使用 XML FAB 标签添加行为

app:layout_behavior="com.example.ScrollingFABBehavior" />

关于java - CollapsingToolbarLayout 和 FloatingActionButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36327801/

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