Shouldn't you convert the getWidth() and getHeight() to *double*s before 
your division?

Thanks.



On Monday, March 18, 2013 9:41:26 AM UTC-5, user123 wrote:
>
> I 4 - colums grid where the items are an image on top and bellow a 
> textview. The image fills all the available width - no padding or anything.
>
> My images will all have exactly the same size.
>
> Now I want that the height of the view adjusts to the width - to keep the 
> images proportional. AFAIK this is not possible with Android's scaling 
> types. So I put this code after I load the bitmap (it's feched from the 
> web):
>
>                 imageView.post(new Runnable() {
>                     @Override
>                     public void run() {
>                         double factor = loadedBitmap.getWidth() / 
> (loadedBitmap.getHeight());
>
>                         int width = imageView.getWidth();  
>                         
>                         int newH = (int)(width * factor);
>                         LinearLayout.LayoutParams params = new 
> LinearLayout.LayoutParams(width, newH);
>                         imageView.setLayoutParams(params);
>                         //convertViewFinal.invalidate(); //doesn't help
>                         //convertViewFinal.requestLayout(); //doesn't help
>                     }
>                 });
>
> It works for most of the images, but on some, it doesn't show any image 
> (the imageview looks like GONE), and in some cases this also breaks the 
> grid layout. Why is it? I know that the bitmaps are fine, because, in my 
> testing application, I loop through the same bitmaps many times - they 
> appear after x items in the grid again, and they are fine. And each time I 
> load the grid, different items have the problem. 
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to