是否可以缩放 drawableleft &textview中的drawableright? [英] Is it possible to scale drawableleft & drawableright in textview?
问题描述
我有 TextView
和 drawableLeft
&列表项中的 drawableRight
.问题是,每当 TextView
的高度较大时,drawableLeft
&drawableLeft
没有根据 TextView
的高度自动缩放.
I have TextView
with drawableLeft
& drawableRight
in List item.
The problem is, whenever the height of TextView
is larger, drawableLeft
& drawableLeft
didn't automatically scale based on the height of the TextView
.
drawableLeft
& 的高度是否可以缩放?TextView
中的 drawableRight
?(我使用的是 9 个补丁图像)
Is it possible to scale the height of drawableLeft
& drawableRight
in TextView
?
(I was using 9 patch image)
推荐答案
这可能会对您有所帮助.有两个属性 scaleX 和 scaleY
This might help you out. There are two properties scaleX and scaleY
下面的代码会将图片和文字缩小 30%.因此,您必须使用那么多sp"来增加字体大小,以便在重新调整大小(缩放)时适合您喜欢的sp".
The code below will scale down the image and the text with 30%. Therefore you have to increase the font size with that many "sp", so that when it get re-sized (scaled) it would fit the "sp" you prefer.
示例.如果我将字体设置为 18,那么 18 中的 30% 是 5.4sp,所以粗略地说,这就是我的目标值,因为当它被缩放时,它会变成 13sp
Example. If I set the font to 18, then 30% out of 18 is 5.4sp, so roughly, this is the value I am targeting at, because when it gets scaled, it would become 13sp
<TextView
android:textSize="18sp"
android:scaleX="0.7"
android:scaleY="0.7"
最后要做的是设置 CompundDrawable.
The last thing to do is set the CompundDrawable.
tview.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.xxx), null, null, null);
这篇关于是否可以缩放 drawableleft &textview中的drawableright?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!