2012-03-04 118 views
1

我使用這樣的佈局:爲什麼圖像的尺寸更大?

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/logo" 
    android:orientation="horizontal" > 

drawable/logo.xml

<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/login_logo" 
    android:gravity="center" /> 

drawable/login_logo.png有280個像素寬度,我Galaxy Tab的屏幕寬度爲600像素,但在推出的應用程序,我看到圖片後幾乎所有的屏幕寬度,它是大約500px

我在哪裏犯錯?

解決
通過設置

<uses-sdk android:minSdkVersion="4" /> 

,並把圖像drawable-hdpi

回答

1

您正在背景中設置圖片,並且android:background標籤使用9個補丁圖像。所以你的背景總是延伸到視圖的寬度和高度。您的佈局寬度設置爲fill_parent,因此圖片寬度也是fill_parent。 解決方案可能是使用.9.png擴展名創建您正在使用的png的9個補丁映像。 閱讀heredrawing 9 patch images - developer.android.com/guide/developing/tools/draw9patch.html

+0

我試圖使用9路圖像,但也有同樣的效果。 – 2012-03-04 11:35:20

+0

你把分數放在正確的位置嗎?我的意思是,如果你想整個圖像轉換爲非strechable你需要把點的長度和寬度 – noob 2012-03-04 11:39:52

+0

是啊,我已經添加了必要的拉伸區..但問題是設備放大每一個它的工作原理與 – 2012-03-04 11:42:02

1

我建議你有documentation的很好看。如果您將圖像放在drawable-mdpi文件夾中,那麼在高密度屏幕中,圖像尺寸將顯示爲1.5倍。您將不得不爲不同的屏幕密度提供不同的圖像分辨率。

+0

我也試過把同樣的圖像放在'drawable-hdpi'中,但是效果相同。 – 2012-03-04 11:33:47

2
  1. 正如你說的是對的Galaxy Tab故drawable-hdpi.So在未來的變化的決議圖像與Photoshop或東西,並把它放在drawable-hdpi裏面。
  2. 並嘗試使用android:layout_width =「wrap_content」。而不是android:layout_width =「fil_parent」