2012-08-15 60 views
0

我很担心Android操作系统如何处理在我的应用程序上调整大小。基本上我有一个480x800(如此宽480px)的背景图像和一个底部也是480px宽的图像。Android:操作系统没有调整大小相同的图像

在Galaxy S(480×800屏幕)一切正常,如下所示:

enter image description here

在Galaxy S3(720x1280),然而,背景是越来越拉伸到720像素宽,但该图像在底部仅640像素宽,如下图所示:

enter image description here

我试图创建一个xhdpi文件夹640x960的图像,但同样的事情发生(背景拉伸至720px,图像只有640px)。我也尝试玩“ScaleType”,但目前还没有运气。

有谁知道为什么操作系统会重新调整大小不同的两个图像,以及如何解决它?

这里的XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@drawable/bg" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/significados" 
     android:layout_gravity="center" 
     android:layout_marginTop="216dp" 
     android:onClick="goToSignificados" 
     /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/ranking" 
     android:layout_gravity="center" 
     android:onClick="goToRanking" 
     /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/engracados" 
     android:layout_gravity="center" 
     android:onClick="goToEngracados" 
     /> 

    <ImageView 
     android:id="@+id/iv1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="60dp" 
     android:clickable="true" 
     android:contentDescription="@string/image" 
     android:onClick="goToMarket" 
     android:src="@drawable/googleplay" /> 

</LinearLayout> 

回答

1

你必须张贴您的个XML得到更具体的答案,但基本上所有的“意见”可以处理图像缩放不同。

在你的榜样,

你可以让你的按钮使用宽度=匹配父母舒展一路。

“背景”默认会伸展,但也可以平铺。 “按钮”将具有最小尺寸的背景尺寸,但会在需要时拉伸(按钮的文字太多)

作为一个附注,您不应该依赖图像的确切像素。你应该看看nine-patch或制作平铺背景,并确保你利用诸如“匹配父,重力等”的东西。

+0

包括XML。我把这个图像转换成了9patch,但它表现方式相同。我也尝试了图像上的“fill_parent”参数,但它仍然没有调整到720. – 2012-08-15 19:37:31

+0

同样的答案适用:使按钮拉伸将“android:layout_width =”wrap_content“更改为”android:layout_width =“match_parent”,但是你正走向错误的道路。你应该看看:http://developer.android.com/guide/practices/screens_support.html – hatcyl 2012-08-15 19:40:14

+0

我查看了关于支持多屏幕的文档,并且我正在完成所有建议的操作。我仍然不明白为什么两幅图像会以不同的比例重新调整大小。此外,“match_parent”和“fill_parent”都不会将该图片的大小调整为720px。我只是尝试了两个。 – 2012-08-15 19:43:31