My view component for this part is created programatically, and I've adjusted the code to have the following (currently in my text-setting method, but the same thing happens if it's in the initial view-create code)public void SetDescription(String description){ mTxtDescription.setText(Html.fromHtml(description)); mTxtDescription.setClickable(true); mTxtDescription.setMaxLines(5); mTxtDescription.setLines(5); //this makes no difference either! mTxtDescription.setSingleLine(false); mTxtDescription.setScrollbarFadingEnabled(true); mTxtDescription.setScrollBarStyle(VERTICAL); mTxtDescription.setMovementMethod(ScrollingMovementMethod.getInstance()); mTxtDescription.invalidate(); //adding this made no difference...}但是它不起作用-文本仍然会填满整个屏幕,并且由于被向下推到0高度而使图像消失了.如何使文本不能超过5行?However it doesn't work- long text still fills the whole screen and the image has vanished due to being pushed down to a height of 0. How can I get the text to never be more than 5 lines?推荐答案尝试删除对 setSingleLine 的调用.并使用 setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE).还要确保将此调用放在 setMaxLines 和 setLines 调用之前.Try removing the call to setSingleLine. And use setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE). It'd also put this call before the setMaxLines and setLines call to be sure.注意: setLines 会覆盖 setMaxLines 和 setMinLines 的设置.Note: setLines overrides the settings of setMaxLines and setMinLines. TextView 在围绕如何显示多个,省略号等各种调用方面存在许多问题.The TextView has many issues surrounding the various calls to how it should display multiple, ellipses, etc. 这篇关于TextView.setMaxLines无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 17:30