2012-08-15 48 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