James Krawczyk James Krawczyk - 5 months ago 14
Android Question

Android Background Image Appears In Eclipse But Not Emulator

I have created a background image from my app, and adding a copy of the image to each of the drawable folders (low, med, high resolution) and then defined the code in the main.xml as follows

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


In Eclipse it shows the background image no problem, but when I run in the emulator is doesn't display. Where is it going wrong?

Answer

Another option about the problem is that you created you Emulator in such a way that the Android OS determines its screen as xhdpi. If an image is placed in drawable resource folder then Android will try to rescale it for the different resolutions. However if the image appears only in some of the resolution folders (lie drawable-ldpi etc) then the image will be served only in this resolutions.

Please, either create folder drawable-xhdpi and place the image also there, or create folder drawable and place the image there. It will be used for backup.

See the documentation about the image folders.

Comments