Reputation: 2050
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?
Upvotes: 0
Views: 5943
Reputation: 36
I was encountering this problem because I was using a color from ?attr
called colorControlActivated
in my xml drawable. Changing that to a hex code ( of the same color) that I defined in my @colors file
solved my problem.
Upvotes: -1
Reputation: 543
Had the same problem.. background would look fine on the preview but on running the app it just didn't show up. Worked once I used a lower def image.
http://developer.android.com/training/basics/supporting-devices/screens.html Creating different folders with different resolutions of the same image allows your app to select the best for the device it's running on.
Upvotes: 0
Reputation: 12134
i tried the layout it works fine. You create a folder named as drawable
similar to drawable-hdpi
. Put your image inside the drawable
folder. It work fine.
Upvotes: 1
Reputation: 11053
Do you get any error message?
Did you set the AVD to the appropriate settings that would actually use the image files you saved in your drawble folders?
Also try to clean the project and run again. Eclipse does not update these files regularly without explicitly cleaning the complete project.
Upvotes: 1
Reputation: 46943
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.
Upvotes: 4