开发者

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. 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 ele开发者_Go百科gant 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜