Created
November 19, 2012 09:46
-
-
Save samma835/4109871 to your computer and use it in GitHub Desktop.
代码中设置Drawable时,按屏幕Density等比例缩放
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
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