使用drawableleft的情況下翩伪,不能直接通過xml修改圖片的大小
此時需要在java代碼中獲取圖片并進(jìn)行設(shè)置
方法如下:
TextView text = (TextView)findViewById(R.id.text);
Drawable[] drawables = text.getCompoundDrawables();
drawables[1].setBounds(100,0,200,200);
text.setCompoundDrawables(drawables[0],drawables[1],drawables[2],drawables[3]);
Drawable[] drawables = text.getCompoundDrawables();
//數(shù)組下標(biāo)0~3分別代表:左上右下
drawables[1].setBounds(100,0,200,200);
//獲取到資源后系瓢,調(diào)用setBounds設(shè)置左上右下的坐標(biāo)點(diǎn),比如這里設(shè)置代表:長是從離文字最左邊開始的100dp處到200dp處蠕啄,寬是從文字上方0dp處往上延伸200dp氮采。
text.setCompoundDrawables(drawables[0],drawables[1],drawables[2],drawables[3]);
//為TextView重新設(shè)置drawable數(shù)組爹橱,沒有圖片可以用null代替腐泻,另外,從上面看出我們也可以直接在java代碼中調(diào)用setCompoundDrawables為TextView設(shè)置圖片岳悟。