本文介绍了Android TextView可绘制,在可绘制和文本之间更改填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在GridLayout
中创建一个在其下方具有可绘制对象的TextView
.
I am creating a TextView
with a drawable underneath, in a GridLayout
.
我想将可绘制对象带到TextView
的中间;我尝试过setCompoundDrawablePadding(-75)
,它仅更改文本的位置.
I want to bring the drawable to the middle of the TextView
; I tried withsetCompoundDrawablePadding(-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);
如何在TextView
的中间设置文字和可绘制对象?
How can I set the text and drawable to the middle of the TextView
?
推荐答案
您需要结合使用drawablePadding
和padding
以获得所需的结果.
You'll need to combine drawablePadding
and padding
to get the desired result.
这篇关于Android TextView可绘制,在可绘制和文本之间更改填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!