【发布时间】:2011-11-20 00:43:40
【问题描述】:
当我添加如下图标时:
etComment = (EditText) findViewById(R.id.et_comment);
Drawable img = getResources().getDrawable( R.drawable.warning );
etComment.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null );
图标调整 EditText 的大小。如何计算 img 大小并将其放入 EditText 而不调整 EditText 大小?
谢谢!
FunkTheMonk
使用 setCompounDrawables() 而不是 setCompoundDrawablesWithIntrinsicBounds() - 您必须手动设置可绘制对象的边界。
我不明白如何手动计算边界。我有 EditText 的高度和宽度:
etComment = (EditText) findViewById(R.id.et_comment);
Drawable img = getResources().getDrawable( R.drawable.warning );
int size = etComment.getHeight();
img.setBounds(0, 0, size, size);
etComment.setCompoundDrawables( img, null, null, null );
但我在不同的屏幕尺寸下有不同的结果。如何计算图标的正确大小和填充?你能帮帮我吗?
【问题讨论】: