当工具栏“展开”时,我只想在 CollapsingToolbarLayout 中显示部分图像作为背景,但无论我为 ImageView
设置什么 scaleType 和大小,它看起来都完全一样每次。
当我尝试缩放时:
activity_profile.xml:
<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="co.magnt.classmagnet.ProfileActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/profile_picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/default_avatar"
android:scaleType="centerCrop"
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:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
如果您能帮助我解决我的问题,我将不胜感激!
编辑:我希望图像看起来像这样
最佳答案
尝试在 ImageView 上设置 android:adjustViewBounds="true"
?
http://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds
关于android - 图像放入 CollapsingToolbarLayout 时会忽略 scaleType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33045148/