我希望能够在CollapsingToolbarLayout内滚动ImageView.那么怎么可能,以及如何设置该图像视图的起始高度?
我的ImageView高度为280p,在活动开始时我要显示200p然后我可以向下滚动以查看图像的其余部分.我在WhatsApp应用程序中看到了类似的东西.
这是一个链接,看看我想要什么:
我的代码:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.yasser.version6.Profile">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:fitsSystemWindows="true"
android:layout_height="@dimen/app_bar_height"
android:layout_width="match_parent"
android:theme="@style/MyMaterialTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/tof" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"
app:popupTheme="@style/MyMaterialTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include
android:id="@+id/content"
layout="@layout/content_profile" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
内容简介代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
tools:showIn="@layout/activity_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.yasser.version6.Profile">
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud) android android-design-library android-collapsingtoolbarlayout
我有一个Android活动,它使用CoordinatorLayout内的CollapsingToolbarLayout来实现滚动/折叠工具栏,其中图像作为背景/横幅.
图像是从互联网上加载的,我事先并不知道它的大小.
我希望工具栏最初是一定高度(160dp),但如果图像大于此值,我想让用户进一步向下滚动以显示图像的其余部分.但是,这绝不应该自动发生.初始状态是160dp高度,但用户应该能够向下滚动以进一步增加图像的高度.
我似乎无法找到正确的高度/ minheight组合来实现这一目标.这甚至可能吗?
这是我的布局:
<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>
Run Code Online (Sandbox Code Playgroud)
横幅图像的高度设置为160dp,它控制工具栏最初的大小,但显然这样我无法将其扩展到160dp之外,因为这是视图的高度.
我尝试将160dp高度设置为CollapsingToolbarLayout或者AppBarLayout没有任何帮助,它总是最大160dp的高度我只能向上滚动(较小的图像)而不是向下,即使图像更大并且ImageView设置为按比例缩放wrap_content.