【发布时间】:2012-07-18 12:05:51
【问题描述】:
我正在阅读Supporting Multiple Screens 的 Android 文档页面,它指出:
“默认情况下,Android 会缩放您的位图可绘制对象(.png、.jpg 和 .gif 文件)和九补丁可绘制对象(.9.png 文件),以便它们在每个设备上以适当的物理尺寸呈现。”
“如有必要,系统会根据当前屏幕密度将可绘制资源缩放到适当的大小。”
最近,我们一直在为我们的应用程序添加平板电脑功能。在横向模式下(也适用于纵向,但我将使用横向作为示例),我们在屏幕左侧有一个带有文本的图像,在右侧有一个按钮。简单的。在开发这个 XML 布局时,我得到这张图片(在 Eclipse 的 XML 编辑器的图形布局部分),在我的 10" 平板电脑上运行应用程序时会发生什么:
但是,当我在 Acer Iconia A200 上运行我的应用程序时,我得到的屏幕截图更像这样:
事实上,您在第二张屏幕截图中看到的“图像”看起来与我在 Android 2.2 MyTouch 手机上看到的图像大小几乎相同,如果不完全相同的话。
因此,我的问题是,为什么 Android 不会像在 XML 编辑器的图形布局中显示的那样重新调整图像的大小(就像在第一个屏幕截图中一样?)
我尝试过的事情:
- 我已将适当缩放的可绘制图像添加到每个
drawable-_ _ _ _文件夹。不过,图像看起来还是一样。 - 我已将图像添加到 ldpi 中,希望它能针对更高分辨率的平板电脑进行扩展 - 但没有。
- 我目前在
drawable文件夹中有那张图片(无扩展名)。尽管如此,同样的行为仍然存在。
有什么建议吗?
编辑:
代码:
<LinearLayout
android:id="@+id/leftLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="@+id/ImageViewLogo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="10dp"
android:background="@android:color/transparent"
android:contentDescription="@+string/logo"
android:scaleType="fitCenter"
android:src="@drawable/logo_red" />
<RelativeLayout
android:id="@+id/layoutBelowImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center" >
... 4 TextViews here...
</RelativeLayout>
</LinearLayout>
【问题讨论】:
-
你可以发布布局吗?
-
代码还是实际截图?
-
XML 布局 - 更容易看到发生了什么。
-
嗯,我提供的 2 个屏幕截图在技术上是 XML 布局 - 我只是模糊了内容。如您所见,它可以很好地模拟图像(橙色) - 但在我的实际平板电脑上运行时它会缩小很多(到手机大小的图像)。
-
我不同意。盲目的,如果这是一个九块图像,你有没有把它设置为背景?如果不是,这是
ImageView的源图像吗?在这种情况下,您是否设置了正确的scaleType并避免使用wrap_content?
标签: android image user-interface drawable