在博客中Design Support Library: Collapsing Toolbar Layout博客文章有一张标题图片,视差效果不错:
在a simple test project at GitHub我正在尝试实现类似的效果 - 但由于某种原因图像被压扁了:
在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" />
但这无济于事 - 标题图片被压扁了:
最佳答案
默认情况下,背景会拉伸(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/