android-appbarlayout 相关问题

AppBarLayout是一个垂直的LinearLayout,它实现了材料设计app bar概念的许多功能,即滚动手势。

如何在Coordinator布局中添加拉动刷新

我在CoordiantorLayout中有一个AppBar和RecyclerView。 SwipeToRefresh 必须全屏,但 RecyclerView 不能向下滚动。 我在 AppBar 中有一个 RecyclerView 和 CoordiantorLayout。 SwipeToRefresh 必须全屏,但 RecyclerView 不能向下滚动。 <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="128dp"/> </com.google.android.material.appbar.AppBarLayout> <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <androidx.swiperefreshlayout.widget.SwipeRefreshLayout android:layout_width="match_parent" android:layout_height="match_parent" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> 如何在没有库的情况下在 Coordinator 布局中添加全屏拉动刷新。 您可以在 AppBar 未完全展开时禁用滑动刷新布局,并在 AppBar 完全展开时启用它。 vAppBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset -> vSwipeRefresh.isEnabled = verticalOffset == 0 }) 我添加了 swipetorefresh 顶层,如上面的答案。我用下面的代码解决了向上滚动的问题。感谢穆罕默德雷扎:) recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener(){ @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int topRowVerticalPosition = (recyclerView == null || recyclerView.getChildCount() == 0) ? 0 : recyclerView.getChildAt(0).getTop(); swipeRefreshLayout.setEnabled(topRowVerticalPosition >= 0); } @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); } }); 尝试将 SwipeRefreshLayout 设置为根父级,如下所示: <?xml version="1.0" encoding="utf-8"?> <androidx.swiperefreshlayout.widget.SwipeRefreshLayout 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"> <androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="128dp" /> </com.google.android.material.appbar.AppBarLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> 我也面临着同样的问题 然后我用编程解决了它 binding.appbar.addOnOffsetChangedListener { _, verticalOffset -> binding.swipeRefreshLayout.isEnabled = verticalOffset == 0 } 要将 SwipeRefreshLayout 与 CoordinatorLayout 和 FloatingActionButton (FAB) 一起使用,您可以按照以下步骤操作: 更新布局 XML: 打开要添加组件的 XML 布局文件。 包括 <androidx.swiperefreshlayout.widget.SwipeRefreshLayout> 元素作为父布局。 在 SwipeRefreshLayout 内部,包含 CoordinatorLayout 和其他视图。 这是一个例子:<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/swipe_refresh_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:elevation="4dp" app:popupTheme="@style/ThemeOverlay.MaterialComponents.Light" app:title="My Toolbar" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_anchor="@id/toolbar" app:layout_anchorGravity="bottom" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab_scroll_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_arrow_upward" app:layout_anchor="@id/recycler_view" app:layout_anchorGravity="bottom|end" app:layout_margin="@dimen/fab_margin" /> </CoordinatorLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

回答 5 投票 0


一个协调器布局上的多个应用栏布局

我想要一个像 Telegram 那样的聊天个人资料屏幕。但有些部分我看不懂。对于那些可能不知道的人来说,它有一个可折叠工具栏,后面有一个滚动内容区域......

回答 1 投票 0

当 NestedScrollView 为空时停止 AppBarLayout 滚动离开屏幕

我有一个相当典型的列表功能,使用 CoordinatorLayout、AppBarLayout、SwipeRefreshLayout 和 RecyclerView - 当 RecyclerView 有足够的内容可以滚动时,页面看起来不错。 W...

回答 5 投票 0

Androidx 滚动视图行为不起作用

切换到 androidx 后,以下代码停止工作。工具栏下方的 TextView 过去可以随内容滚动,但现在不能了。只有当我设置相同的时候我才能让它工作

回答 3 投票 0

如何减少jetpack中导航图标和标题之间的水平空间组成“TopAppBar”?

我正在 jetpack compose 中制作一个应用程序栏,但导航图标和标题之间存在间距问题。 这是我的撰写功能: @可组合 fun DetailsAppBar(硬币: 硬币, backAction: ...

回答 3 投票 0

CoordinatorLayout + AppBarLayout + NavigationDrawer

将 CoordinatorLayout 与 AppBarLayout 和 NavigationDrawer 组合时遇到布局问题。 问题是,NavigationDrawer 及其内容隐藏在工具栏后面。 ...

回答 3 投票 0

如何在andoid上进行垂直列表导航?

你能告诉我如何实现这个行为吗? AppBar 下有一个水平菜单,可以让您转到所需的类别、列表位置,并且当

回答 1 投票 0

Material Design 3 顶部应用栏没有阴影。如何启用它?

新的“Material Design 3 top app bar”文档说他们摆脱了阴影。 我怎样才能启用它?在 Toolbar 或 AppBar 上设置高度根本不起作用。

回答 2 投票 0

Fragments 中的 CoordinatorLayout + scrollFlags 没有正确隐藏菜单并在隐藏时破坏其他 fragments,滚动时 FAB 也会丢失

我开始了一个新项目。我读过那个单一的活动,许多片段是一种常见的推荐方法。我有一个 MainActivity 和 3 个片段。此设置仅来自“...

回答 1 投票 0

仅在向上滚动时在折叠工具栏布局中启用快速滚动

仅当滚动方向向上时,我才尝试在应用栏布局中的折叠工具栏中启用快速滚动。就像向上滚动 50% 的应用栏内容应该展开或折叠工具栏。

回答 0 投票 0

如何在 Compose UI 的 topBar 上显示内容

嗨,我想实现内容应该与顶部栏重叠。在 XML 中,我使用了高程和负填充,并且效果很好。我很难在 Compose UI 中做到这一点。 到目前为止我所拥有的。

回答 1 投票 0

如何在坐标布局中修改 Imageview 的行为

我希望我的 imageView 在折叠工具栏达到一定高度时消失

回答 1 投票 0

如何通过编程改变AppBarLayout的偏移量?

我们可以通过appBarLayout.addOnOffsetChangedListener看到偏移量的变化,但是如何用编程的方式改变偏移量呢? 像appBarLayout.setOffset(y: Float)

回答 1 投票 0

在AppBarLayout中用MaterialToolbar将标题居中。

我试着将我的工具栏中的文本居中。我使用AppBarLayout和MaterialToolbar,正如Material Design中建议的那样。我尝试了我在StackOverflow上找到的所有方法来使标题居中,但似乎没有任何效果。

回答 1 投票 -1


工具栏未显示在Android的API 21以下

当在API 21下运行时,工具栏未显示。目前,我正在API 19仿真器中运行此应用。此相同布局可在运行于API 21以上且等于API 21的设备中正常工作。

回答 1 投票 3

完全展开时折叠式工具栏底部的工具栏菜单项

我的菜单中有项目,但它本身在折叠的工具栏中。我想做的是,当折叠工具栏折叠时,菜单项在顶部,当...

回答 1 投票 0

NestedScrollView不在CoordinatorLayout中滚动-Android

以下布局中的嵌套滚动视图未滚动。如果删除协调器布局,则进行滚动工作。但是,我想保留协调器布局以将fab按钮放置在底部...

回答 1 投票 1

如何在AppBarLayout Android中删除SearchView的查询文本中的下划线

我在我的应用中使用AppBarLayout搜索小部件。一切正常,但我完全无法删除AppBarLayout中搜索字段下方的下划线。以下是废话代码。 ...

回答 1 投票 1

© www.soinside.com 2019 - 2024. All rights reserved.