我的活动具有以下布局:
<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-工具栏下的布局不会消失
您可以向其中添加一个空标题,GridView
该标题将隐藏在您的自定义标题下,以提供所需的间距。由于standartGridView
不支持标头,因此您需要使用HeaderGridView
。我已多次使用此小部件,并且始终可以正常工作。
由于您正在使用SwipeRefreshLayout
,因此还需要调整其进度视图的位置。根据此答案,可以使用来完成setProgressViewOffset()
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句