当我像下面这样添加图标:
etComment = (EditText) findViewById(R.id.et_comment);
Drawable img = getResources().getDrawable( R.drawable.warning );
etComment.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null );
这个图标会调整EditText的大小。我如何计算图像大小并将其放入EditText中,而不使EditText调整大小呢?
谢谢!
FunkTheMonk
使用setCompoundDrawables()而不是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 );
但是在不同的屏幕尺寸下,我的结果不同。我如何计算图标的正确大小和填充?你能帮我吗?