【发布时间】:2015-08-24 05:54:04
【问题描述】:
我在片段中使用 FAB 按钮和 RecyclerView。这个 Fragment 是 TabViewPager 的一个实例。我遇到了 FAB 按钮的问题。我已将 RecyclerView 和 fab 按钮放置在 FrameLayout 内,FAB 按钮位于右下角。现在我面临的问题是 FAB 按钮不完全可见。它的一半部分被隐藏,如下面的屏幕截图所示。谁能帮我解决这个问题。提前致谢。
注意: FAB 在滚动后会正确对齐。只有在理想情况下才会出现问题(在滚动完成之前)。
fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="10dp"
app:backgroundTint="@color/red"
android:src="@drawable/ic_done"/>
</FrameLayout>
tabviewpagerlayout.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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.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:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</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>
【问题讨论】:
-
注意,我没有使用新的设计库...但是...可能是FAB默认为关闭屏幕。尝试删除它的边距。当您滚动(向上?)时,FAB 应该会出现。向下滚动应将其删除。这样 FAB 就不会妨碍您在 RecyclerView 上的最后一行。在这种情况下,会有一个辅助功能可以让 FAB 随意出现。
-
实际上在滚动期间它工作正常。但是当它处于理想模式时,就会出现问题,就像上面附上的屏幕截图一样。看起来很别扭。
-
为什么不试试
RelativeLayout而不是FrameLayout? -
我也通过分配 alignparent_bottom 和 alignparent_right="true" 尝试使用 RelativeLayout。也是无奈。表现得一样。我认为问题在于 CoordinatorLayout 属性
-
我面临同样的问题。在我的情况下,这是由于工具栏上的 layout_scrollFlags 属性引起的。当此属性设置为“scroll|enterAlways”时,您会注意到视图会变大一点,以便能够向上滚动并隐藏工具栏。将其设为静态将“解决”此问题。如果您确实找到了解决方法,请告诉我们。
标签: android android-fragments floating-action-button androiddesignsupport android-coordinatorlayout