【问题标题】:Resize drawable in TextView在 TextView 中调整可绘制对象的大小
【发布时间】:2015-10-28 17:59:08
【问题描述】:

我正在使用以下代码将可绘制对象附加到 TextView

TextView tv = new TextView(this);
        tv.setText(text);
        tv.setTextSize(55);
        tv.setBackgroundResource(R.drawable.bubble);
        tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.presence_offline, 0);

drawable 已显示,但唯一的问题是它与文本相比非常小,我想重新缩放它并使其更大,但我还没有找到方法。

这是可绘制对象的外观。有什么建议吗?

【问题讨论】:

标签: android textview drawable


【解决方案1】:

您可以将其转换为 9-patch drawable。

9-patch drawable 是一个可根据其内容进行拉伸的可绘制对象,非常适合为视图制作背景。 9-patch 可绘制对象通过以 .9.png 扩展名结尾来检测,并且只是常规可绘制对象,其中图像的第一行和最后一行和列用于确定应该拉伸的部分以及应该保持相同的部分。

有一个工具可以从常规图像中创建 9-patch 可绘制对象,称为 Draw 9-patch 工具,它位于 android sdk 目录的 tools 子目录中,对于 windows 为 {SDK}\tools\draw9patch.bat

9-patch documentation on the android dev site

Draw 9-patch tool documentation on the android dev site

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    相关资源
    最近更新 更多