0

I have a ViewFlipper and I inflate the first View multiple times to get the same Layout in each child.

I put some images in the assets folder which I want to load and put it each child of the ViewFlipper.

My problem is that these images aren`t as big as the inflated ImageView. All images in the assets have the same size 450x450.

Is it normal that the loaded pictures are scaled smaller, when they are loaded from the assets? Or is the problem somewhere else?

I know that I can put the images in the drawable directory, but I want to have my images in the assets.

for(int i =0;i< createArray();i++){         
        flipper.setDisplayedChild(i);

        ImageView pic = (ImageView) flipper.getCurrentView().findViewById(R.id.ImageView01);
        ImageView pic2 = (ImageView) flipper.getCurrentView().findViewById(R.id.ImageView02);

        try {               
            Drawable d1 = Drawable.createFromStream(getAssets().open("product-overview"+File.separator+"psu"+File.separator+fileNames[i]+File.separator+"product_pic_full.png"), null);
            Drawable d2 = Drawable.createFromStream(getAssets().open("product-overview"+File.separator+"psu"+File.separator+fileNames[i]+File.separator+"product_pic_background.png"), null);

            pic.setImageDrawable(d1);
            pic2.setImageDrawable(d2);



        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
    }

As explanation: I load the pictures dynamically from assets. My assets folder has sub-folders because the overview is much better. I load them and every ViewFlipper- child gets his own picture : Frontside and Backside. Everything is working fine. But the images aren`t 450x450 as the pictures in assets.

Maybe it`s not a good method to change the views. But it works for me.

Billabong
  • 457
  • 2
  • 8
  • 23
  • when decoding the bitmap from the assets, you can add some options to the BitmapOptions so that it won't scale it, including avoiding density properties. can you please show the code? – android developer Jun 19 '13 at 11:20
  • I edit my question. Hope it helps – Billabong Jun 19 '13 at 11:42
  • i don't understand the upper area of the code and it looks like you're doing something really wrong (depends on what "createArray" does) , but for the decoding, try to use this instead : http://stackoverflow.com/a/8501428/878126 . if needed, add bitmapOptions for the decoding : http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options) – android developer Jun 19 '13 at 11:48
  • createarray() is a method to get the number of views the viewflipper should have. As I said it`s dynamic. The number of views depends on the number of subfolders in assets. I think this isn`wrong. :) i`m going to test your advice. – Billabong Jun 19 '13 at 12:06
  • this is funny. with my drawable method these pictures are small. but with your method they are bigger but not 450x450 .... – Billabong Jun 19 '13 at 12:26
  • well if it's not dynamic between iterations of the for-loop, it should be outside of it,since it's called on each iteration. about the decoding, try to set the "inScaled" to false or the "inDensity" of the bitmapOptions to be the same as the current screen density. it depends on what you want from the bitmap to be. android treats images in regard to the screen density, so it can't know what you want from it without you telling it what to do. – android developer Jun 19 '13 at 12:48
  • I have the solution. Keyword is density.... assets doesn`t have hdpi etc. folders thanks ;) – Billabong Jun 19 '13 at 13:23
  • i should have written it in an answer then. will you tick my answer if i wrote it again? – android developer Jun 19 '13 at 13:35

0 Answers0