2012-04-28 22 views
0

我從我的應用程序創建了一個背景圖像,並將圖像的副本添加到每個可繪製文件夾(低,中,高分辨率),然後在main.xml如下Android背景圖像出現在Eclipse但不是仿真器

<?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" > 

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.57" 
     android:background="@drawable/scrollviewtexture"> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="90dp" 
      android:text="Memorable" 
      android:textAppearance="?android:attr/textAppearanceMedium" android:typeface="sans"/> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textView1" 
      android:layout_centerHorizontal="true" 
      android:text="(Swipe To Generate Password)" 
      android:textAppearance="?android:attr/textAppearanceSmall" android:textSize="5pt"/> 

    </RelativeLayout> 

</LinearLayout> 

在Eclipse中它顯示的背景圖像沒有問題,但是當我在模擬器中運行時不顯示。哪裏出問題了?

+0

你使用PNG圖像嗎? – sandalone 2012-04-28 07:05:27

+0

clean ur項目並嘗試再次運行 – Khan 2012-04-28 07:05:36

+0

圖像實際存儲在哪個目錄下:'drawable'或一些'drawable-ldpi','drawable-hdpi','drawable-mdpi','drawable- xhdpi'? – 2012-04-28 07:13:03

回答

3

關於該問題的另一個選擇是,您創建了一個模擬器,Android操作系統將其屏幕確定爲xhdpi。如果圖像放在drawable資源文件夾中,則Android會嘗試重新調整其分辨率。但是,如果圖像僅出現在某些分辨率文件夾中(如drawable-ldpi等),則圖像將僅以此分辨率進行投放。

請創建文件夾drawable-xhdpi並將圖像放在那裏,或創建文件夾drawable並將圖像放置在那裏。它將用於備份。

查看documentation關於圖片文件夾。

+0

我嘗試添加一個可繪製文件夾,然後是drawable-xhdpi但沒有區別。 – jskrwyk 2012-04-28 18:42:45

+0

解決了它。刪除了佈局並重新添加並且工作正常。保持文件夾名稱「drawable」 – jskrwyk 2012-04-29 02:30:13

1

您是否收到任何錯誤訊息?

您是否將AVD設置爲實際使用您保存在可拖曳文件夾中的圖像文件的適當設置?

也嘗試清理項目並再次運行。沒有明確清理整個項目,Eclipse不會定期更新這些文件。

+0

沒有錯誤代碼,除了關於使用NSQuickDrawView的警告,因爲它已過時。我試過清洗它。 AVD上的設置可能會對此產生什麼影響? – jskrwyk 2012-04-28 18:44:00

+0

根據屏幕設置,系統可能會採用不同分辨率可繪製文件夾中的不同png文件 – user387184 2012-04-28 20:16:01

1

我試過它的工作正常的佈局。您創建一個名爲drawable的文件夾,類似於drawable-hdpi。將您的圖片放入drawable文件夾中。它工作正常。

+0

嘗試過,並且在運行時仍然不會出現在AVD中 – jskrwyk 2012-04-28 18:39:11

-1

我遇到了這個問題,因爲我在我的xml drawable中使用了?attr中的一個顏色colorControlActivated。將其更改爲我在我的@colors file中定義的十六進制代碼(具有相同顏色)解決了我的問題。