• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to add a background image in main.xml in anyother directory structure except @drawable

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 162
1
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just curious to know when should we ideally use assets folder ???
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at this http://www.compiletimeerror.com/2013/01/how-to-set-background-image-in-android.html for your problem, may help...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic