[英]android:textview adjusts itself to wrong layout_width
<TextView
android:layout_height="wrap_content"
android:id="@+id/LineNumberTextView"
android:hint="Number"
android:textSize="15sp"
android:layout_width="wrap_content"
android:paddingRight="10sp">
</TextView>
The above code creates a wrong view: when the text is replaced (in code) to a short (1-3 digits) number, the view width stays about 6 characters - resulting in way too much padding. 上面的代码创建了一个错误的视图:当文本(用代码)替换为短数字(1-3位数字)时,视图宽度保持大约6个字符-导致太多的填充。 This problem occurs in some other places in the application too. 应用程序中的其他一些地方也会发生此问题。 One option is to set the hint to 1-3 characters - but this seems ugly, and doesn't solve the problem for too-long text (which also suffers from hint width problems). 一种选择是将提示设置为1-3个字符-但这看起来很丑陋,并且不能解决文本太长的问题(也存在提示宽度问题)。 Therefore, I'm looking for a more elegant solution (which does not require recalculating width on each change), if there is one. 因此,如果有的话,我正在寻找一种更优雅的解决方案(不需要在每次更改时都重新计算宽度)。
BTW, the input text is set exactly once for each occurrence of this layout, when loading it into some list view (but it's dynamic and unknown when loading the application). 顺便说一句,将这种文本每次加载到列表视图中时,都会为该布局的每次出现设置一次准确的设置(但是在加载应用程序时它是动态的并且是未知的)。 Problem is most severe in android 2.1, but appears in some other platforms too. 问题在android 2.1中最为严重,但在其他一些平台上也出现过。
set "minems" as per your requirement, so that your textview will streached to a proper width. 根据您的要求设置“元素”,以便将textview拉伸到适当的宽度。 set a "maxems" so that it will limited to a certain width. 设置“最大值”,以便将其限制为一定的宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.