android - 折叠工具栏的视差效果不起作用,标题中的图像被压扁

标签 android parallax android-toolbar android-design-library android-coordinatorlayout

在博客中Design Support Library: Collapsing Toolbar Layout博客文章有一张标题图片,视差效果不错:

app screenshot

a simple test project at GitHub我正在尝试实现类似的效果 - 但由于某种原因图像被压扁了:

app screenshot

activity_main.xml我已经为 scaleType 尝试了所有可能的值,但图像仍然失真:

        <ImageView
            android:id="@+id/header_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/header"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

请问我在这里遗漏了什么?

更新:

我已尝试按照 Apurva 的建议更改为 match_parent(感谢 +1):

        <ImageView
            android:id="@+id/header_image_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/header2"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

但这无济于事 - 标题图片被压扁了:

app screenshot 1

app screenshot 2

最佳答案

默认情况下,背景会拉伸(stretch)以适合。您应该在 ImageView 上设置 android:src 而不是 android:background

<ImageView
    android:id="@+id/header_image_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/header2"
    android:scaleType="centerCrop"
    app:layout_collapseMode="parallax" />

关于android - 折叠工具栏的视差效果不起作用,标题中的图像被压扁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31774038/

相关文章:

javascript - 根据另一个 div 滚动位置显示 div

javascript - 使用jQuery根据scrollTop位置显示div

javascript - ScrollMagic 元素在页面加载时自动触发

android - CardView 内的工具栏,用于创建弹出菜单(溢出图标)

android - 如何更改 Lollipop 之前和 Lollipop 版本的工具栏菜单项文本颜色

android - 工具栏上均匀分布的菜单项

Android Studio : Is creation of a signing configuration necessary when creating a custom build type?

java - 我在 android studio 中使用什么来进行多个 Activity ?

android - InMobiBanner 未初始化

带复选框的 Android 可过滤回收 View