Android TextView 可绘制,更改可绘制和文本之间的填充? [英] Android TextView drawable, change padding between drawable and text?

查看:29
本文介绍了Android TextView 可绘制,更改可绘制和文本之间的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 GridLayout 中创建一个 TextView,下面有一个可绘制对象.

I am creating a TextView with a drawable underneath, in a GridLayout.

我想把drawable放到TextView的中间;我试过了setCompoundDrawablePadding(-75),它只改变文本的位置.

I want to bring the drawable to the middle of the TextView; I tried with setCompoundDrawablePadding(-75) and it only changes the position of the text.

当前代码:

    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);

如何将文本和drawable设置在TextView的中间?

How can I set the text and drawable to the middle of the TextView?

推荐答案

你需要结合 drawablePaddingpadding 来获得想要的结果.

You'll need to combine drawablePadding and padding to get the desired result.

这篇关于Android TextView 可绘制,更改可绘制和文本之间的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆