I need a square block of 20% of the screen,
If i get a width of 100 DP then i also need height of 100 DP.
How to achieve this in android with the use of weight?
I need a square block of 20% of the screen,
If i get a width of 100 DP then i also need height of 100 DP.
How to achieve this in android with the use of weight?
You can do like this
public void setImageSize(byte[] imageThumbnail)
{
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Bitmap bitmapOrg = new BitmapDrawable(getResources(), new ByteArrayInputStream(imageThumbnail)).getBitmap();
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
float scaleWidth = metrics.scaledDensity/5;
//set image in imageView
imageView.setImageBitmap(bitmapOrg);
//set imageView dynamic width and height
imageView.getLayoutParam().width = scaleWidth;
imageView.getLayoutParam().height= scaleWidth;
}
Or
Maybe try a different approach...you can create SquareImageView to scaling of images to screen density of width and height.