如何在按钮上显示动态文本并在Android中自动调整其大小? [英] How to display dynamic text on a button and auto adjust their size in Android?

查看:96
本文介绍了如何在按钮上显示动态文本并在Android中自动调整其大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,该项目需要我根据用户在按钮上的选择显示一些动态文本.

I'm working on a project which needs me to display some dynamic texts based on users' selection on a button.

我知道如何显示文本,但是我对如何在固定大小的按钮上正确显示其他文本感到困惑.

I know how to do the text display part, but I was stuck on how I can display different text properly on a fixed size button.

例如:苹果"和我有一个苹果".我如何获得这样的结果:当显示苹果"时,文本大小会变大并适合按钮;当显示我有苹果​​"时,文本会变小并可能变成三行?

For example: "Apple" and "I have an Apple". How can I achieve the result that when displaying "Apple", the text size will be bigger and fit the button, and when "I have an Apple" the text will be smaller and may become three lines?

谢谢!

推荐答案

看看这个问题

Take a look at this question Auto Scale TextView Text to Fit within Bounds. The same technique should apply to a button.

(是的,它比看起来应该的要复杂得多.)

(yes, it is much more complicated than it seems like it should be.)

这篇关于如何在按钮上显示动态文本并在Android中自动调整其大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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