我有一个使用CollapsingToolbarLayout的Android活动,该活动位于CoordinatorLayout内部,以实现具有图像作为背景/横幅的滚动/折叠工具栏。 图像从互联网加载,我不知道其大小。
我希望工具栏最初是一定高度(160dp),但如果图像大于此高度,则希望允许用户向下滚动以显示其余部分。 但是,这不应自动发生。 初始状态为160dp高度,但用户应能够向下滚动以进一步增加图像的高度。
我似乎找不到正确的高度/最小高度组合来实现这一点。 这是否可能?
以下是我的布局:
横幅图像的高度设置为160dp,这控制了工具栏的初始大小,但显然我无法将其扩展到160dp之外,因为那是视图的高度。
我尝试将160dp高度设置为CollapsingToolbarLayout或AppBarLayout,但没有任何帮助,它始终最大为160dp高度,并且我只能向上滚动它(较小的图像),而不能向下滚动,即使图像要大得多并且ImageView设置为按wrap_content缩放。
以下是我想要实现的示意图,以防不清楚:
我希望工具栏最初是一定高度(160dp),但如果图像大于此高度,则希望允许用户向下滚动以显示其余部分。 但是,这不应自动发生。 初始状态为160dp高度,但用户应能够向下滚动以进一步增加图像的高度。
我似乎找不到正确的高度/最小高度组合来实现这一点。 这是否可能?
以下是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/toolbar_text">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
android:fitsSystemWindows="true">
<!-- The background banner -->
<ImageView
android:id="@+id/imgBanner"
android:layout_width="match_parent"
android:layout_height="160dp"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:theme="@style/AppToolbarTheme" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
...
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
横幅图像的高度设置为160dp,这控制了工具栏的初始大小,但显然我无法将其扩展到160dp之外,因为那是视图的高度。
我尝试将160dp高度设置为CollapsingToolbarLayout或AppBarLayout,但没有任何帮助,它始终最大为160dp高度,并且我只能向上滚动它(较小的图像),而不能向下滚动,即使图像要大得多并且ImageView设置为按wrap_content缩放。
以下是我想要实现的示意图,以防不清楚: