android-coordinatorlayout 相关问题

CoordinatorLayout是一个超级动力的FrameLayout。

如何在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


带有 RecyclerView 和折叠标题的 CoordinatorLayout

我的布局如下: (工具栏, 标题视图、文本视图、RecyclerView) 当我滚动 recyclerview 的项目时,我需要折叠标题。 这样视图“选择项目”和

回答 3 投票 0

在 CoordinatorLayout 中的工具栏下方添加视图

我有以下布局: 我有以下布局: <android.support.design.widget.CoordinatorLayout android:id="@+id/main_content" 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"> <android.support.design.widget.AppBarLayout android:id="@+id/appBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.design.widget.CoordinatorLayout> 我将 Fragment 添加到 FrameLayout 中,替换它们。我的 Fragment 之一是一个列表,其布局如下: <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 我的问题是工具栏绘制在列表上。我尝试通过将 CoordinatorLayout 的内容包装到 LinearLayout 中来解决这个问题,这解决了透支问题,但这样应用程序栏滚动行为就不再起作用。 非常感谢任何帮助! 获取属性 app:layout_behavior="@string/appbar_scrolling_view_behavior" 从 RecyclerView 上取下并将其放在您要在 FrameLayout 下显示的 Toolbar 上。 我发现滚动视图行为所做的一件重要的事情是将组件布局在工具栏下方。因为 FrameLayout 有一个会滚动的后代 (RecyclerView),所以 CoordinatorLayout 将获取用于移动 Toolbar 的滚动事件。 另一件事要注意:布局行为将导致 FrameLayout 高度调整大小 就好像 Toolbar 已经滚动,并且随着 Toolbar 完全显示,整个视图被简单地向下推,因此视图的底部低于 CoordinatorLayout 的底部。 这对我来说是一个惊喜。我期望随着工具栏上下滚动,视图会动态调整大小。因此,如果您的视图底部有一个带有固定组件的滚动组件,则在完全滚动 Toolbar 之前,您将看不到该底部组件。 因此,当我想在 UI 底部锚定一个按钮时,我通过将按钮放在 CoordinatorLayout (android:layout_gravity="bottom") 的底部并在视图中添加等于按钮高度的底部边距来解决此问题工具栏下方。 我设法通过添加来解决这个问题: android:layout_marginTop="?android:attr/actionBarSize" 像这样到FrameLayout: <FrameLayout android:id="@+id/content" android:layout_marginTop="?android:attr/actionBarSize" android:layout_width="match_parent" android:layout_height="match_parent" /> 使用折叠顶部工具栏或使用您自己选择的 ScrollFlags 我们可以这样做:从Material Design摆脱FrameLayout <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="match_parent" app:contentScrim="?attr/colorPrimary" app:expandedTitleGravity="top" app:layout_scrollFlags="scroll|enterAlways"> <androidx.appcompat.widget.Toolbar android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin"> <ImageView android:id="@+id/ic_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_arrow_back" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="back" android:textSize="16sp" android:textStyle="bold" /> </androidx.appcompat.widget.Toolbar> </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> <androidx.recyclerview.widget.RecyclerView android:id="@+id/post_details_recycler" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="5dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> 从 Android studio 3.4 开始,您需要将此行放入包含 RecyclerView 的布局中。 app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" 看一下。尝试给予与工具栏相同大小的边距 <?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" android:fitsSystemWindows="true" app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" tools:context=".MainActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" /> </com.google.android.material.appbar.AppBarLayout> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/constraintLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" app:layout_anchor="@+id/constraintLayout" app:layout_anchorGravity="center" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

回答 5 投票 0

Fab 没有被底部导航上方的小吃栏推上来

(这个错误发生在一个大项目中,所以我做了一个小项目以便于演示) 我已经被这个问题困扰了一段时间,但我在任何地方都找不到答案 ~布局 我...

回答 2 投票 0

协调器布局内的SearchView

我如何实现以下布局设计,在向上滚动时我只需使用 searchview 获得视图: 1 ---- 2------向上滚动: 我尝试过将视图放在布局中的某些位置,但是

回答 3 投票 0

CoordinatorLayout + AppBarLayout + NavigationDrawer

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

回答 3 投票 0

包裹在 CoordinatorLayout 内的 RecyclerView 在键盘打开时未调整大小

活动布局xml: 活动布局xml: <?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" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginEnd="64dp" app:expandedTitleMarginStart="48dp" app:layout_scrollFlags="scroll"> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" app:layout_collapseMode="parallax"> <ImageView android:layout_width="match_parent" android:layout_height="250dp" android:scaleType="centerCrop" android:src="@drawable/hospital_logo" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:orientation="vertical" android:padding="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="******* ************* ********** ************" android:textSize="18sp" android:textColor="@android:color/black" android:textStyle="bold"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="***************************" android:textSize="18sp" android:textColor="@android:color/black" android:textStyle="bold"/> </LinearLayout> </FrameLayout> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> </android.support.design.widget.CollapsingToolbarLayout> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabMode="fixed" /> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.CoordinatorLayout> 这里我将 CoordinatorLayout 与 CollapsingToolbarBar 和 ViewPager 一起使用。 我在 ViewPager 中添加了两个带有布局 xml 的片段: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" /> </LinearLayout> recycler_view 的单元格包含 EditText。当我选择 EditText 时,软键盘打开,但 EditText 隐藏在键盘后面。 我已在活动中添加了以下标志: android:windowSoftInputMode="adjustResize" 我正在使用 23.1.1 appcompat 版本的 RecyclerView。 当我用 CoordinatorLayout 替换 LinearLayout 时,RecyclerView 正在调整大小以正确显示最后一个元素。所以我认为这是协调器布局的问题。 我遇到了以下问题https://code.google.com/p/android/issues/detail?id=176406和https://code.google.com/p/android/issues/detail?id =176187 但这与这个错误无关。让我知道我是否可以应用某种路径来解决这个问题。 等待回复。谢谢。 如果需要更多详细信息,请告诉我。 有一个非常相似的问题,并且能够通过使用 android:windowSoftInputMode="adjustPan" 来修复它 我遇到了类似的问题coordinatorLayout。但是,将 fitsSystemWindows 设置为 false 解决了问题。看来罪魁祸首是coordinatorLayout。我通过将整个布局(包括 AppBarLayout)封装在 constraintLayout 中解决了这个问题。 <androidx.coordinatorlayout.widget.CoordinatorLayout> <androidx.constraintlayout.widget.ConstraintLayout <com.google.android.material.appbar.AppBarLayout </com.google.android.material.appbar.AppBarLayout //content here </androidx.constraintlayout.widget.ConstraintLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout> 我知道回复这个帖子来得很晚,但也许对其他人有帮助。 :)

回答 2 投票 0

在滚动 Android 上具有折叠视图的布局

我的布局包含三个视图:视图 A、视图 B 和一个 RecyclerView。视图 A 在上面,视图 B 在视图 A 下面。然后,RecyclerView 在视图 B 下面。我想实现以下行为:当

回答 0 投票 0

折叠工具栏布局不会折叠

我有一个折叠的工具栏布局,它有两个问题: 1)它是静态的,不会崩溃,我找不到原因 2) recyclerview 中的最后一行显示一半

回答 4 投票 0

如何仅在滚动对屏幕来说太大的 RecyclerView 时才使用 MotionLayout 隐藏/显示视图?

我有一个用于搜索的片段。它的布局在顶部有一个“搜索栏”,然后是我显示结果的 TextView 和 RecyclerView。我想隐藏/

回答 0 投票 0

让无尽的 RecyclerView 内容包裹在 CoordinatorLayout 中

我想显示一个工具栏、详细布局和带有分页/无限列表的回收器视图。我最终使用 CoordinatorLayout 来包含详细布局和 RecyclerView,以及 ReyclerView

回答 0 投票 0

Android:RecyclerView 不在 CoordinatorLayout 内滚动

我有自定义的 LinearLayout,可以根据它包含的内容将高度设置为最大或最小。但是如果这个 LinearLayout 里面有 RecyclerView,当我调用

回答 1 投票 0

Android - 当 Fab 设置了 layout_behavior 时,无法使 FloatingActionButton 在显示 snackbar 时向上移动

在我的应用程序中,我有一个屏幕,在协调器布局中有一个晶圆厂。当显示小吃店时,工厂会随着小吃店的出现而向上移动(这是我所期望的)。 然而,在另一个屏幕上,我的 ...

回答 0 投票 0

在 CoordinatorLayout 中展开两个相互对立的视图

我的协调器布局中有两个视图,基本上是图像视图和嵌套滚动视图(作为底部工作表行为)。 当底页上下滑动时,图像应根据...调整大小

回答 0 投票 0

页面内容与 CoordinatorLayout 中的 Toolbar 和 SearchBar 重叠

每当我尝试在 Android Studio 中创建带有 SearchBar 的 CoordinatorLayout 时,页面其余部分的内容会与 SearchBar 和我创建的 MaterialToolbar 重叠。 我试过更换

回答 0 投票 0

material BottomNavigationView 在键盘启动时隐藏图标

我有一个简单的 BottomAppBar 和 BottomNavigationView 材料,我看到一个奇怪的行为:每次它显示在键盘上方(添加这个栏的活动有 android:windowSoftInput ...

回答 0 投票 0

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

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

回答 1 投票 0

CoordinatorLayout - 如何为锚定视图设置动画

我有 CoordinatorLayout 父级,在这个父级内部是布局 bottomSheetContainer,它将包含 BottomSheet,它附有 BottomSheetBehaviour。然后在它上面有锚...

回答 0 投票 0

在CoordinatorLayout中,Supportmapfragment不工作。

我试图把我的GoogleMaps片段放到CoordinatorLayout中,结果出现了错误。以前的xml只有GoogleMaps片段,当时它工作正常。

回答 1 投票 0

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