Skip to content

Instantly share code, notes, and snippets.

@samma835
Created November 19, 2012 09:46
Show Gist options
  • Save samma835/4109871 to your computer and use it in GitHub Desktop.
Save samma835/4109871 to your computer and use it in GitHub Desktop.
代码中设置Drawable时,按屏幕Density等比例缩放
bd = new BitmapDrawable(tmpInfo.bitmap);
try {
Method m = BitmapDrawable.class.getMethod(
"setTargetDensity",
new Class[] { DisplayMetrics.class });
m.invoke(bd, GlobalInfo.currentActivity.getResources()
.getDisplayMetrics());
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
view.setBackgroundDrawable(bd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment