我的布局由封面图像(英雄图像),工具栏和列表视图组成。
在新的材料设计指南(如在此清单上看到的:tangible surfaces上,当我滚动列表视图时,封面图像应位于工具栏和列表视图的后面,然后工具栏应滚动到顶部。
在Google i / o 2014应用中,您可以在会话活动下看到此功能。问题在于他们使用的是内部包含所有内容的ScrollView。
如何用列表视图来做同样的事情?
[编辑]:发布新的设计支持库(http://android-developers.blogspot.co.uk/2015/05/android-design-support-library.html)之后,解决方案将使用带有recyclerview的协调器布局。但是还是要感谢@Endor!
您可以将FrameLayout
用作根,将ImageView
作为封面的第一个子项,然后将ListView
作为第二个子项。
喜欢这个:
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:id="@+id/tv_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_light"
android:gravity="center"
android:text="@string/app_name"
android:textColor="@android:color/black"
android:textSize="24sp" >
</TextView>
<ListView
android:id="@+id/lv_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#CA8500"
android:dividerHeight="1dp" >
</ListView>
</merge>
显然,ListView将阻止ImageView,因此这里的技巧是向ListView添加一个透明标题,其高度与封面ImageView相同。
然后,当用户向上滚动ListView时,ImageView将被ListView的实际内容覆盖。