我正在创建一个带有drawable的TextView
,并将其放在GridLayout
中。
我想将drawable放在TextView
的中间; 我尝试使用setCompoundDrawablePadding(-75)
,但这仅更改了文本的位置。
当前代码:
TextView secondItem = new TextView(this);
GridLayout.LayoutParams second = new GridLayout.LayoutParams(row2, col1);
second.width = halfOfScreenWidth;
second.height = (int) (quarterScreenWidth * 1.5);
secondItem.setLayoutParams(second);
secondItem.setBackgroundResource(R.color.MenuSecond);
secondItem.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, R.drawable.ic_action_new);
secondItem.setText("Text");
secondItem.setCompoundDrawablePadding(-180);
secondItem.setGravity(Gravity.CENTER);
secondItem.setTextAppearance(this, android.R.style.TextAppearance_Large_Inverse);
gridLayout.addView(secondItem, second);
我该如何将文本和可绘制物设置到 TextView
的中间?