0

i have a gifview class that load a gif in function of screen size in this way:

if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL){
        gif = "anim_cerca_ldpi.gif";
    }else if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL){
        gif = "anim_cerca_mdpi.gif";
    }else{
        gif = "anim_cerca_hdpi.gif";
    }

The problem is that i try it on galaxy S II and image taken is anim_cerca_ldpi.gif so the small size one. can you help me finding what could be the error?

Jayyrus
  • 12,961
  • 41
  • 132
  • 214

2 Answers2

1

The much better way to do this is to create directories like res/drawable-ldpi, res/drawable-mdpi, etc. and put these files in the respective dirs, named anim_cerca.gif. Then simply load them by loading resource ID R.drawable.anim_cerca. It will automatically choose the right one for your device.

PS: You are checking the screen size, but seem to be selecting resources defined for different screen densities. These are different things, too.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • i try to use drawable folders but i have problem with gif! if you saw http://stackoverflow.com/questions/7777315/showing-gif-in-android i've created a class to show gif in android and it works only with file in assets and not in drawable! – Jayyrus Nov 24 '11 at 10:26
0

You shouldn't decide programmatically in this case. (I say so because of what you want to achieve with the code you posted. maybe in other cases a programmatically choice is what you'd need)

Have you tried splitting your drawables in their proper folders (drawable-hdpi | mdpi | ldpi)? if you do so, android OS will load the proper resource for you.

STT LCU
  • 4,348
  • 4
  • 29
  • 47