【问题标题】:How to get max lines of Text如何获得最大文本行数
【发布时间】:2011-12-10 12:12:27
【问题描述】:

如何获取TextView可以写的最大行数?我试过这个:

DisplayMetrics metrics = new DisplayMetrics ();
getWindowManager (). getDefaultDisplay (). getMetrics (metrics);
float width = metrics.widthPixels;
float height = metrics.heightPixels;

int lines = (int) (height / textView.getLineHeight ());

System.out.println (lines);

但是,此变体提供了错误的信息。

【问题讨论】:

    标签: android text textview line


    【解决方案1】:

    textview.getLineCount()

    一切尽在documentation

    编辑:我有点太快了。我假设您想要文本视图中可以包含的行数,而不是文本视图中当前有多少行...在这种情况下 -> 看看这个问题:Calculate text size according to width of text area

    【讨论】:

      【解决方案2】:

      textview.getLineCount() 会帮助你

      【讨论】:

        【解决方案3】:
        textView.getHeight() / textView.getLineHeight()
        

        textView.getHeight()textView.getLineHeight() 都会以屏幕dpi 考虑屏幕高度。

        这是获得正确视图高度的帖子。 View's getWidth() and getHeight() returns 0

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-08-16
          • 2019-11-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多