【发布时间】:2012-03-02 20:52:15
【问题描述】:
这是我的基本布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:adjustViewBounds="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/welcome_hero" />
</LinearLayout>
我希望图像在保持纵横比适合屏幕的同时进行缩放,并向下推动任何后续视图。
这在我的 mdpi (LG LGP509) 和 hdpi (HTC G2, Nexus One) 设备上运行良好。但是,在我的 Galaxy Nexus (xhdpi) 上,图像顽固地无法缩放以适应。它在侧面留下了额外的空间。
这里有更多信息:
布局位于通用布局/文件夹中
welcome_hero.png 位于 drawables/ 文件夹中,宽度为 320 像素,高度为 161 像素
AndroidManifest.xml 有这个条目:
<uses-sdk
android:targetSdkVersion="10"
android:minSdkVersion="8" />
<supports-screens
android:xlargeScreens="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="false" />
我尝试过的一些事情:
- 将 scaleType 更改为 fitCenter、fitInside 或 matrix 会产生与不使用相同的结果
- 将 ImageView 高度更改为 fill_parent 可以正确缩放图像,但会将所有其他视图推离屏幕
- 用身体暴力威胁监视器让我更加沮丧
- 将高度和宽度显式设置为 320dp,而 161dp 没有任何改变
- 如上所述,我在 IntelliJ 的预览器和物理设备上都尝试了新布局
我已经浏览了 StackOverflow 大约 1.5 小时,查看了数百个与我相似的帖子,但似乎没有一个可以在 Galaxy Nexus 上运行。我正在拼命努力成为一名优秀的开发人员,并将我的东西扩展到新手机,但事实证明这很困难。
【问题讨论】:
标签: android android-layout android-imageview android-2.2-froyo android-4.0-ice-cream-sandwich