我正在TextView中创建一个带有可绘制下方的GridLayout

我想将可绘制对象带到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的中间?

最佳答案

您需要结合drawablePaddingpadding以获得所需的结果。

关于android - Android TextView可绘制,在可绘制和文本之间更改填充?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19362762/

10-10 16:37