【发布时间】:2013-10-22 04:01:34
【问题描述】:
我正在创建一个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);
如何将 text 和 drawable 设置到 TextView 的中间?
【问题讨论】:
标签: android textview drawable padding