How ImageView fitCenter algorithm works , i have a image_hight and image_width , i need to programmatically implement the centerFit ,, but i'm having no luck with it ,, i tried t scale image like this
newPostHolder.height = DeviceHigh;
int heightOfImage = data.getInt("image_height");
if (heightOfImage > ((newPostHolder.height / 100) * 80) || heightOfImage == newPostHolder.height) {
heightOfImage = ((newPostHolder.height / 100) * 69);
}
newPostHolder.one_imageview.getLayoutParams().height = heightOfImage;
And like this
int heightOfImage = 0;
int widthOfImage = 0;
float scalingRatio = ((Float.parseFloat(heightOfImage) / Float.parseFloat(widthOfImage));
viewHolder.imageLoadingLayout.getLayoutParams().height = Math.round(scalingRatio*width );
the first one big images still looks tall and the second one do some type of blurring on images.
My question is how can i scale the image like the fitCenter scale ??
it seems that the second code works like the fitCenter my problem was that i do a check before fixing the size and thats check cuzes the problem
int heightOfImage = data.getInt("image_height");
int widthOfImage = data.getInt("image_width");
heightOfImage = newPostHolder.width * heightOfImage / widthOfImage;
newPostHolder.one_imageview.getLayoutParams().height = heightOfImage;
newPostHolder.one_imageview.getLayoutParams().width = newPostHolder.width;