app:layout_scrollFlags不起作用

http://stackoverflow.com/questions/31722798/enteralwayscollapsed-does-not-bring-back-the-toolbar-when-scrolling-down/31946043#31946043

1.enterAlwaysCollapsed: 当你的视图已经设置minHeight属性又使用此标志时,你的视图只能已最小高度进入,只有当滚动视图到达顶部时才扩大到完整高度

2. 含有app:layout_scrollFlags的view必须声明在不含该属性的view的布局的前面

 
 

Hard to say without seeing your code, as a guess this could be one of two things:


1.

enterAlwaysCollapsed - This flag defines how View enter back into the screen. When your view has declared a minHeight and you use this flag, your View will only enter at its minimum height (i.e., ‘collapsed’), only re-expanding to its full height when the scrolling view has reached it’s top. Use it with scroll flag like this: scroll|enterAlwaysCollapsed

Anyway it seems like it doesn't work as described in minHeight part.

 


2.

You have not formatted your code correctly.

From Android's Developer Blog I quote on "CoordinatorLayout and the app bar":

One note: all views using the scroll flag must be declared before views that do not use the flag. This ensures that all views exit from the top, leaving the fixed elements behind.

This link also goes into more detail about how to use enterAlwaysCollapsed and is worth looking at.

 

转载于:https://www.cnblogs.com/krislight1105/p/5080798.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个问题可能与AppBarLayout的滚动效果有关。当你动态设置一个View为GONE时,AppBarLayout会重新计算滚动范围,但是由于布局文件中的空白区域已经被占用了,新的滚动范围可能会出现空白占位问题。 解决办法是在AppBarLayout中使用`app:layout_scrollFlags="scroll|exitUntilCollapsed"`,并且在你要隐藏的View上添加`app:layout_collapseMode="pin"`。这样当你隐藏这个View时,AppBarLayout会自动调整滚动范围,并且不会出现空白占位问题。 示例代码如下: ```xml <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="200dp" android:scaleType="centerCrop" android:src="@drawable/image" app:layout_collapseMode="parallax" /> <TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:text="Title" android:textColor="@android:color/white" android:textSize="24sp" app:layout_collapseMode="pin" /> <View android:id="@+id/view" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="visible" app:layout_collapseMode="pin" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> ``` 在代码中,我把你要隐藏的View的`android:visibility`属性设置为`visible`,这样在初始状态下它会被显示出来。当你要隐藏它时,可以使用`view.setVisibility(View.GONE)`方法。AppBarLayout会根据你隐藏的View自动调整滚动范围,不会出现空白占位问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值