给一个Button添加图片
private void setViewDrawable(int drawableid, TextView view, int driection) {
Drawable drawable = getResources().getDrawable(drawableid);
drawable.setBounds(0, 0, 100, 100);
Drawable[] drawables = new Drawable[4];
drawables[driection] = drawable;
view.setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3]);
view.setCompoundDrawablePadding(0);
}
使用
setViewDrawable(R.drawable.addphoto, addphoto2, 1);