Skip to content

Instantly share code, notes, and snippets.

@mr5z
Last active September 3, 2015 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr5z/477cd2598cb103c5d3ce to your computer and use it in GitHub Desktop.
Save mr5z/477cd2598cb103c5d3ce to your computer and use it in GitHub Desktop.
protected void setModuleInterface(Context context, int resourceImageId) {
int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceImageId);
float aspectRatio = bitmap.getWidth() / (float) bitmap.getHeight();
int height = Math.round(screenWidth / aspectRatio);
bitmap = Bitmap.createScaledBitmap(bitmap, screenWidth, height, true);
BITMAP_WIDTH = bitmap.getWidth();
BITMAP_HEIGHT = bitmap.getHeight();
setBackground(new BitmapDrawable(context.getResources(), bitmap));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment