android - Toolbar下的GridView——滚动时隐藏ToolBar

标签 android gridview toolbar material-design

我的 Activity 有以下布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/content_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

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

</FrameLayout>

content_fragment 是我替换包含 gridView 的 fragment 的地方:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.test.android.client.fragment.BurgerGridFragment">

        <GridView
            android:id="@+id/grid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:columnWidth="150dp"
            android:horizontalSpacing="@dimen/margin_extra_small"
            android:numColumns="auto_fit"
            android:padding="@dimen/padding_extra_small"
            android:scrollbars="none"
            android:stretchMode="columnWidth"
            android:verticalSpacing="@dimen/margin_extra_small" />

    </android.support.v4.widget.SwipeRefreshLayout>

我的想法是,只要我在 GridView 中滚动,工具栏就应该随动画出现/消失:

if (shown) {


view.animate()
                    .translationY(0)
                    .alpha(1)
                    .setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        } else {
            view.animate()
                    .translationY(-view.getBottom())
                    .alpha(0)
                    .setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        }

问题是第一个网格项与工具栏部分重叠。 你知道如何解决这个问题吗?

附录:

我已经为我的 Activity 尝试使用 RelativeLayout 和 LinearLayout 而不是 FrameLayout,但这不是解决方案,我遇到了另一个问题,如 https://stackoverflow.com/questions/29163698/hiding-toolbar-when-scrolling-layout-under-toolbar-does-not-disapear 所述

最佳答案

尝试将 FrameLayout 更改为垂直方向的 LinearLayout。 然后 Gridview 将放置在工具栏下方。

关于android - Toolbar下的GridView——滚动时隐藏ToolBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29182185/

相关文章:

xaml - 使用 x :Bind inside the GridView's ItemTemplate layout User Control in UWP

c++ - wxWidgets 工具栏文本对齐

JQuery UI 工具栏按钮布局

android - RecyclerView 位于工具栏下方

java - Utils 类中的自定义 Toast

android - 尝试在 Android 中打开文件的错误路径

安卓文件创建

android - "Use Facebook Login"SDK编译错误

android - 如何删除 gridview 单元格中的额外空间 - Android

c# - 排序 GridView