【问题标题】:Setting the text of TextView that fits the screen Height and Width independently of the text size of TextView设置适合屏幕高度和宽度的 TextView 的文本,与 TextView 的文本大小无关
【发布时间】:2011-02-09 12:22:19
【问题描述】:

如果我将它显示为 TextView,我有一个非常大的字符串将无法显示在屏幕中。谁能告诉我如何选择一个完全适合屏幕高度和宽度的子字符串,而与 TextView 的文本大小无关。

【问题讨论】:

    标签: android


    【解决方案1】:

    将这些属性添加到 xml 中的 TextView

       android:singleLine="true"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
    

    【讨论】:

    • 嗨 Javanator,你误解了我的问题,我不是在寻找单行 TextView,我想要一个适合整个屏幕的 TestView。我正在寻找确切的字符数。
    • 如果视图更大,那么屏幕大小和文本大小不会受到影响,然后将 textview 放在具有 fill_parent 高度和宽度的滚动视图中
    • 您好 Javanator,感谢您的评论。我正在尝试开发一个 epub 阅读器。如果文本不适合当前屏幕,我想在两页中显示 TextView。为此,我需要适合屏幕的确切字符数。
    • 这完全取决于文本字体大小。您使用 Display 和 WindowManager 类计算可用屏幕的总宽度,然后计算适合一行的字符数,从而类似地计算屏幕中的行数..
    • 显示显示 = getWindowManager().getDefaultDisplay(); int 宽度 = display.getWidth(); int height = display.getHeight();
    猜你喜欢
    • 1970-01-01
    • 2019-01-06
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    相关资源
    最近更新 更多