贴代码:
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <!--向上滚动会隐藏的部分要设置app:layout_scrollFlags="scroll"--> <include layout="@layout/item_dynamic_list_item_detail_item" app:layout_scrollFlags="scroll"/> <android.support.design.widget.TabLayout android:id="@+id/tl_tab_dynamic_list_item_detail" android:layout_width="match_parent" android:layout_height="wrap_content" app:theme="@style/ThemeOverlay.AppCompat.Dark" android:background="@color/colorPrimary"/> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/vp_dynamic_list_item_detail" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> </android.support.design.widget.CoordinatorLayout> 说明:上面代码的"include"Tag是引入一个头部布局,而我想实现的效果 是在上移时将这部分隐藏,但效果就是不出来。
尝试:我将上面提到的”include”外面再嵌套一层LinearLayout,效果出来了,直接贴代码吧!
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <!--向上滚动会隐藏的部分要设置app:layout_scrollFlags="scroll"--> <LinearLayout app:layout_scrollFlags="scroll" android:layout_width="match_parent" android:layout_height="wrap_content"//换成LinearLayout嵌套设置使用,可行 android:orientation="vertical"> <include layout="@layout/item_dynamic_list_item_detail_item"/> </LinearLayout> <android.support.design.widget.TabLayout android:id="@+id/tl_tab_dynamic_list_item_detail" android:layout_width="match_parent" android:layout_height="wrap_content" app:theme="@style/ThemeOverlay.AppCompat.Dark" android:background="@color/colorPrimary"/> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/vp_dynamic_list_item_detail" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> </android.support.design.widget.CoordinatorLayout>
总结:采用”include”引入布局的方式,在include所在的”<>”里为其布局设置属性可能是无效的,因为我也 没尝试其他嵌套设置属性的情况,…有时间将继续探讨
关于在项目中使用Android5.0的CoordinatorLayout,上滑无效果的问题
最新推荐文章于 2022-12-21 22:28:06 发布