简体   繁体   English

android:textview将自身调整为错误的layout_width

[英]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.

相关问题 使用layout_width =“ wrap_content”获取TextView的可用宽度 - Get available width for TextView with layout_width=“wrap_content” 在Android中以编程方式设置EditText的layout_width - Programatically set layout_width of EditText in Android Android 数据绑定 layout_width 和 layout_height - Android Data Binding layout_width and layout_height Android自定义组件:找不到layout_width属性 - Android custom component: layout_width attribute not found 如何在Android中修复提供的layout_width属性 - How to fix supply a layout_width attribute in Android 如何根据 Android 布局中的 layout_width 指定 layout_height 值? - How can I specify the layout_height value based on the layout_width in Android layout? 在Android应用中获取消息:二进制XML文件第2行:您必须提供layout_width属性 - Getting message in android app: Binary XML file line #2: You must supply a layout_width attribute 在 package 'android' / new pacakge 中找不到属性 'layout_width' 的资源标识符 - No resource identifier found for attribute 'layout_width' in package 'android' / new pacakge 从strings.xml提供layout_height和layout_width - Provide layout_height and layout_width from strings.xml layout_width/height 如何与最小/最大宽度/高度一起工作 - How does layout_width/height work together with min/max width/height
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM