在代码中设置文本与图片的相对位置时,可以用setCompoundDrawables(left, top, right, bottom)方法。
方法非常简单首先需要使用setBounds(int left, int top, int right, int bottom)给图片设置边界,然后再使用
setCompoundDrawables(left, top, right, bottom)方法设置图片的位置。
Drawable drawable = getResources().getDrawable(R.drawable.back_arrow);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
goBackTextView.setCompoundDrawables(null, null, null, drawable);