I created a static function like this.
public static Bitmap Bitmap(String path) {
Bitmap bitmap = Bitmap
.getBitmapResource(Display.getWidth() + "/" + path);
System.out.println(Display.getWidth() + "" + path);
return bitmap;
}
However, when I called like this,
private Bitmap download = Config_GlobalFunction.Bitmap("btn_download.png");
The output gave me FRIDG could not find 320/btn_download.png.
In my res folder, I got an folder which was img and inside img got 6 different folders which were 160, 240, 320, 360, 480 and 640 folder.
How can I call correct folder’s image based on Display.getWidth()?
It is possible to have a folder hierarchy under the
/resfolder but you must usegetClass().getResourceAsStream(path)rather thanBitmap.getBitmapResource()in order to create your resource.This example creates a Bitmap from the path
/res/img/hi_res/ui/action_arrow.png:It’s a bit more work but it does mean you can have a nice folder structure, rather than hundreds of images lumped together in a single folder.