| Author |
How to add a background image in main.xml in anyother directory structure except @drawable
|
Arslan Asif
Greenhorn
Joined: Jun 12, 2010
Posts: 8
|
|
Hello
I am trying to use this but it is giving error
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="/assets/images/mybackgrounds/bg.png"
I want to know how can we give background image at a particular location in layout file like main.xml
|
 |
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
Welcome to JavaRanch Asif!
If you have your image resource in drawable folder you can refer them as follows:
android:background="@drawable/resource_name".
If you bundle them in assets, then you will have to read these files as streams using AssetManager and then create a Bitmap from these stream using BitmapFactory. After this is done, you can set this Bitmap as background property of your View or ViewGroup in code.
Putting an image resource in drawable folder is NOT JUST copying an image file to a folder in the Project's structure.(Read official documentation on Application Resources). Android tools(aapt et al.) do a lot of stuff behind the scenes.
|
[List of FAQs] | [Android FAQ] | [My Blog] | [Samuh Varta]
|
 |
Sahil Rally
Greenhorn
Joined: Jan 12, 2013
Posts: 28
|
|
|
Just curious to know when should we ideally use assets folder ???
|
 |
Ragavan Raju
Greenhorn
Joined: Dec 28, 2012
Posts: 5
|
|
|
Have a look at this http://www.compiletimeerror.com/2013/01/how-to-set-background-image-in-android.html for your problem, may help...
|
 |
 |
|
|
subject: How to add a background image in main.xml in anyother directory structure except @drawable
|
|
|