簡體   English   中英

工具欄下的GridView - 滾動時隱藏工具欄

[英]GridView under Toolbar - Hide ToolBar when Scrolling

我的活動有以下布局:

<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的片段的地方:

<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());
        }

問題是第一個網格項與toolBar部分重疊。 你知道如何解決這個問題嗎?

附加物:

我已經為我的Activity嘗試了RelativeLayout以及LinearLayout而不是FrameLayout,但這不是一個解決方案,我遇到了另一個問題,如https://stackoverflow.com/questions/29163698/hiding-toolbar-when-scrolling-布局下的工具欄-不-不disapear

嘗試將FrameLayout更改為LinearLayout,方向為vertical。 然后Gridview將放置在工具欄下方。

您可以向GridView添加一個空標題,該標題將隱藏在您的自定義標題下,以提供所需的間距。 由於標准GridView不支持標題,因此您需要使用HeaderGridView 我已經多次使用過這個小部件了,它總是運行良好。

由於您使用的是SwipeRefreshLayout您還需要調整其進度視圖位置。 根據這個答案,可以使用setProgressViewOffset()來完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM