1

我在 Android 文档页面上阅读Supporting Multiple Screens,它指出:

“默认情况下,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>
4

1 回答 1

1

scaleTypeImageView. 在这种情况下,您可能希望使用fitCenter来保持纵横比。

模拟器和真实设备之间仍然存在一些不一致之处。

为避免使用但保持(with )wrap_content的纵横比,您可以尝试以下操作:ImageViewfitCenter

  • 将其设置为fill_parent。在 a 中使用权重LinearLayout(建议避免嵌套权重,但不是关键)。
  • 将其设置为fill_parent。正确使用layout_abovelayout_below
  • 创建一个自定义视图,扩展ImageView并设置正确的纵横比OnMeasured
  • 设置一个固定的宽度和高度 dp(最简单的)。
于 2012-07-18T12:30:31.030 回答