Last active
October 30, 2017 05:54
-
-
Save shaon2016/1655f7f29c4379671e58abbe5fb15158 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int imageHeight, imageWidth, w; | |
private ImageView imageSingleFoodItem; | |
onCreate() { | |
// w = (int) (getScreenWidth(this) * 0.80); | |
w = (int) (getScreenWidth(this)); | |
//drawable image and you want that size you can get like this way | |
BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inJustDecodeBounds = true; | |
BitmapFactory.decodeResource(getResources(), R.drawable.food3, options); | |
imageHeight = options.outHeight; | |
imageWidth = options.outWidth; | |
imageSingleFoodItem.getLayoutParams().height = (int) Math.ceil((imageHeight * w) / imageWidth); | |
imageSingleFoodItem.getLayoutParams().width = w; | |
imageSingleFoodItem.requestLayout(); | |
imageSingleFoodItem.setImageResource(R.drawable.food3); | |
} | |
public static int getScreenWidth(Context context) { | |
return context.getResources().getDisplayMetrics().widthPixels; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment