Mau*_*ice 4 android imagebutton
有没有办法获得当前设置的图像的尺寸ImageButton?我正在努力实现这一目标.
我ImageButton的默认图片为36 x 36.然后我选择尺寸为200 x 200的图片.我想打电话给:
imageButton.setImageBitmap(Bitmap.createScaledBitmap(
bitmap, 36, 36, true));
Run Code Online (Sandbox Code Playgroud)
将图像缩小到36 x 36.我想要获得原始图像大小的原因是为了满足hdpi,mdpi和ldpi,所以我可以将位图的尺寸分别设置为36 x 36,24 x 24和18 x 18把它添加到ImageButton.有任何想法吗?
哦,伙计,我随机摆弄代码后得到了答案:
imageButton.getDrawable().getBounds().height();
imageButton.getDrawable().getBounds().width();
Run Code Online (Sandbox Code Playgroud)
试试这个代码 -
imageButton.getDrawable().getBounds().height();
imageButton.getDrawable().getBounds().width();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3036 次 |
| 最近记录: |