I’m trying to make a slide show app, but cannot figure out how to get the pictures to display in the background. This is what I was going to do
I was going to use the background property of a LinearLayout.
The problem is that the setBackgound takes in a resourceid,
From previous experience, you cannot have a lot of images stored as resoucrs,
so I was going to store them in the asset folder and load them in using the following code
try {
String FileName=new String("background");
AssetManager assetManager= getAssets();
InputStream inputStream;
inputStream=assetManager.open(FileName);
Bitmap Background=BitmapFactory.decodeStream(inputStream);
} catch( IOException e)
{
Is there a way to load a asset into the background property?
I have used a ImageView before, but I wanted the images to be in the background so I could draw the controls ontop of the image. I’v seen this done in other Gallery programs.
Does anybody now a way to load pictures from assets and have them in the background with the controls on top, or another way to do this?
You have to use
View.setBackground(Drawable)( http://developer.android.com/reference/android/view/View.html#setBackground(android.graphics.drawable.Drawable) )Once you have an bitmap loaded from asset, you can create
BitmapDrawableand pass it to the method above.As the commenter below noticed, you have to use now-deprectated
setBackgroundDrawableto be compatible with older android versions.