最近在做一个仿海词词典的demo,首页主要用到了CoordinatorLayout 折叠标题,并加载下方不同布局的数据。海词词典的的首页是非常漂亮的,先让我们看下它的首页吧。直接上图片
这里我们可以看到,首页向上滑动的过程中,只有上部分滑出了屏幕,而搜索框并没有,而是滑到了屏幕的上方看上去非常漂亮
在下边的listview中,装载了不同布局的item(可以看到第一部分和第二部分的布局是不同的),那这是怎么实现的呢?具体我不清楚人家是用的什么方法,但是我使用了
CoordinatorLayout 的折叠标题功能实现了上滑折叠功能,然后下边是用了
RecyclerView嵌套了不同布局的item,刚开始做的时候我没有使用RecyclerView而是直接用的ListView嵌套不同布局的item,但是做成后没有折叠效果,查了网上的资料后发现在RecyclerView中的layout_behavior是对折叠效果支持的,具体用listview怎么实现,能否实现?小弟bu知,望大神指点!
下边看下我做的demo吧
1、CoordinatorLayout
先看下我的整个布局文件activity_mainsearch.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="180dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/photo"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="top"
android:minHeight="?attr/actionBarSize"
app:popupTheme="