android:textview 将自身调整为错误的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>
上面的代码创建了一个错误的视图:当文本(在代码中)替换为短数字(1-3 位)时,视图宽度保持在 6 个字符左右 - 导致填充过多。该问题也出现在应用程序的其他一些地方。一种选择是将提示设置为 1-3 个字符 - 但这看起来很难看,并且不能解决文本太长的问题(这也存在提示宽度问题)。因此,我正在寻找一种更优雅的解决方案(如果有的话,不需要在每次更改时重新计算宽度)。
顺便说一句,当将输入文本加载到某个列表视图中时,每次出现此布局时,输入文本都会设置一次(但在加载应用程序时它是动态且未知的)。这个问题在android 2.1中最为严重,但在其他一些平台上也出现了。
<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. 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). 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的要求设置“minems”,以便您的文本视图将拉伸到适当的宽度。设置一个“maxems”,使其限制在一定的宽度。
set "minems" as per your requirement, so that your textview will streached to a proper width. set a "maxems" so that it will limited to a certain width.