- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想放置一个 FrameLayout
用于托管 Fragments
, BottomNavigationView
和一个 FAB
里面CoordinatorLayout
.我想显示一个 Snackbar
过BottomNavigationView
和 FAB
上下移动以容纳Snackbar
.我想出了以下布局,但我无法获得 Snackbar
和 FAB 行为正确。
<?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:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".landingpage.MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.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" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/fragment_cont"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_main_activity_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/extended_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="16dp"
android:layout_marginBottom="72dp"
android:contentDescription="@string/cont_desc"
android:text="@string/chat"
app:icon="@drawable/ic_baseline_chat_24" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
如果我像这样设置 LayoutParams
post然后该边距 72dp 边距也显示为在布局中向上抛出 FAB。如果我不使用边距,FAB 将堆叠在
BottomNavigationView
上。 .我可以用
addCallback以编程方式设置 FAB 边距。然后它也会跳跃,然后将自己对齐到正确的位置。总的来说,在用户体验方面,这不是一个好的体验。
最佳答案
I would like to display a
Snackbar
over theBottomNavigationView
and FAB to move up and down to accommodate theSnackbar
. I have comeup with the following layout but I am unable to getSnackbar
and FABbehavior correctly.
BottomNavigationView
和
FAB
一起。实际上更常用的是
FAB
&
BottomAppBar
在
底部的布局。
Then also it will jump and then align itself to the right position.Overall it is not a good experience UX wise.
CoordinatorLayout
内LinearLayout
(支持 FAB
动画):
<?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"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:title="Test" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/fragment_cont"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/SnackBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/extended_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:text="Chat"
android:textColor="@color/white"
app:icon="@drawable/ic_baseline_send_24"
app:iconTint="@color/white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_insetEdge="bottom"
app:menu="@menu/escrow_menu" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
在 Kotlin 方面:
extended_fab.setOnClickListener {
val snack: Snackbar = Snackbar.make(SnackBar, " Successfully ...!", Snackbar.LENGTH_SHORT)
snack.show()
}
BottomAppBar
& FAB & setAnchorView()
没有 FAB
的方法动画
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<androidx.core.widget.NestedScrollView
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!-- your FrameLayout maybe -->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="SHOW SnakeBar"
app:layout_anchor="@+id/content_layout"
app:layout_anchorGravity="center" />
</androidx.core.widget.NestedScrollView>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:title="Test" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
app:layout_anchor="@id/bar" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:backgroundTint="@color/colorPrimaryDark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="@drawable/ic_baseline_send_24"
android:gravity="center"
android:orientation="vertical"
android:text="Personal"
android:textColor="#FFFFFF">
</TextView>
<TextView
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="@drawable/ic_baseline_send_24"
android:gravity="center"
android:orientation="vertical"
android:text="Personal"
android:textColor="#FFFFFF">
</TextView>
<TextView
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="@drawable/ic_baseline_send_24"
android:gravity="center"
android:orientation="vertical"
android:textColor="#FFFFFF"
android:visibility="invisible">
</TextView>
<TextView
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="@drawable/ic_baseline_send_24"
android:gravity="center"
android:orientation="vertical"
android:text="Personal"
android:textColor="#FFFFFF">
</TextView>
<TextView
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="@drawable/ic_baseline_send_24"
android:gravity="center"
android:orientation="vertical"
android:text="Personal"
android:textColor="#FFFFFF">
</TextView>
</LinearLayout>
</com.google.android.material.bottomappbar.BottomAppBar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
FAB
- BottomNavigationView
- ConstraintLayout
没有 FAB
动画
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_margin="16dp"
app:backgroundTint="@color/colorPrimary"
app:elevation="10dp"
app:layout_constraintBottom_toTopOf="@id/navigation"
app:layout_constraintLeft_toRightOf="@id/navigation"
app:layout_constraintRight_toLeftOf="@id/navigation"
app:layout_constraintTop_toBottomOf="@id/navigation"
app:layout_constraintTop_toTopOf="@id/navigation"
app:layout_insetEdge="bottom" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimaryDark"
android:visibility="visible"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/escrow_menu" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="290dp"
android:layout_marginBottom="485dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
关于android - 在 CoordinatorLayout 中排列一个 BottomNavigationView、一个 FAB 和一个 FrameLayout 并使其与 Snackbar 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63166438/
根据我目前的阅读,Behavior 只能应用于 CoordinatorLayout 的直接子级。但是下面的代码让我感到困惑:
CoordinatorLayout 在另一个 CoordinatorLayout 中,这样滚动 subview 也应该滚动父 CoordinatorLayout。 我有一个 coordinatorLa
我正在创建一个 Android 应用程序,我想隐藏 BottomAppBar (它有一个固定在中心的工厂)每当我滚动 RecyclerView谁在我的 Activity fragment 内而不更改
我提到了 This Question但没有答案对我有用。所以基本上我有一个 BottomNavigationView,它在向下滚动时隐藏并在向上滚动时显示。当我通过触摸滚动 Recycler View
我想向 CoordinatorLayout 添加一个页脚,其中包含一个 TabView + ViewPager。 这是 main.xml:
我有一个 CoordinatorLayout 并且我想要一个 FrameLayout 位于所有其他 Layouts 和 widgets 之下。我试过使用 android:layout_below/ab
我想用 RecyclerView 和 Toolbar 创建简单的 CoordinatorLayout,但与标准解决方案的区别在于 Toolbar 应该在底部,并且当 RecyclerView 滚动到底
我可以在我的 xml 文件中使用协调器布局,但是当我尝试将它导入我的 java 类时,它说“无法解析符号 CoordinatorLayout,而同一包中的其他类工作正常。 截图如下: 依赖项: 最佳答
我正在使用单个 Activity - 多个 fragment 结构。在 Activity 中,我使用 v7 工具栏作为操作栏。我有一些带有 viewpager 的 fragment ,有些也带有标签。
这让我抓狂。这两天我一直在努力完成这项工作,但没有取得任何进展。我想要一个应用程序栏,它在我向下滚动 ViewPager 时隐藏,并在我向上滚动 ViewPager 时显示,这似乎是标准的做法。
我需要创建一个具有线性布局的 Coordinatorlayout 和一个具有相同空间的 RecyclerView。 我试过将 layout_weight 设置为 0.5,但 RecyclerView
我尝试通过 CoordinatorLayout 获得此结果,但无法在背景上设置全屏图像,该图像在整个屏幕上展开,与图像中相同。我尝试了几种方法,例如将 LinearLayout 放入 Collapsi
我有一个包含 3 个使用回收 View 的 fragment 的 viewpager。当用户滚动回收 View 时,我试图隐藏工具栏。我的问题是工具栏在用户滚动时隐藏/显示但没有完全隐藏。我不明白我做
我有一个抽屉的主要 Activity ,抽屉有一个容器布局,我用 FragmentManager 替换每个 fragment 。 我想在滚动上隐藏/显示的我的一个子 fragment 中添加一个 FA
这里我有一个相当复杂的动画,可以使用 CoordinatorLayout 以简单的方式解决(我相信) .它有 3 个状态: 初始(左侧屏幕)- 标题 View 完全显示(橙色 背景):工具栏,灰色 r
我有一个全屏显示的 Activity。这适用于我尝试过的许多布局,但当 CoordinatorLayout 是根 ViewGroup 时除外。 CoordinatorLayout 本身的宽度和高度都设
看看下面的布局。您会看到, float 按钮距离底部太远。这是因为显示了 Toolbar 和 Tabs,并且 ViewPager 的高度不正确。所以不知何故我在 layout_height 上做错了什
我是 android Material 设计方面的新手。所以,请多多包涵。我尝试为我的家庭 Activity 实现 FAB,然后实现 snackbar 。自然,它高于我的 FAB。我研究了 Coord
我正在尝试从新发布的 Android Design Support Library 中实现 CoordinatorLayout并且我根据示例 here 在我的 XML 布局中使用了以下代码:
我正在尝试使用 RecyclerView 和 TextView 实现 CoordinatorLayout,其中 TextView 将根据您滚动 RecyclerView 的方式进行动画处理。但是我的自
我是一名优秀的程序员,十分优秀!