开发者

How to prevent TextView from resizing its container

开发者 https://www.devze.com 2023-03-27 09:50 出处:网络
Take a look at my layout http://pastebin.com/6tQVm3Rk My problem is that the textviews (named header1 to 5) are resizing its containers when a certain amount of letters are written into it, although

Take a look at my layout http://pastebin.com/6tQVm3Rk

My problem is that the textviews (named header1 to 5) are resizing its containers when a certain amount of letters are written into it, although there is still some space left.

What changes do I have to make that the layout stays in its original state independent from the amount 开发者_运维知识库of text located in the headers?


This might be because of this attribute.

android:inputType="textMultiLine"

If you want your textview to have only one line you can use android:singleline="true"


Add the attribute

android:maxLength="2"

to the textview. This way you can limit the number of characters.


I think its better to use Relative layout instead Linear layout in the XML so that objects in Relative layout are easy to manage dynamically, all you need to do is that put all those text views in the Relative layout and set these parameters:

layout align left: layout align right:

And other solution which is not appropriate is that fix the size of text view then it will not expand.

And please see the Documentation for further details of Relative Layout.


Set the width and heigth of your textview to a fixed amount of dp. This will prevent the textview from streching beyond the width and height you declared. Like this:

android:layout_width="50dp"
android:layout_heigth="50dp"


For me the solution was to use

android:layout_width="0dp"

together with

android:maxLines="1"
0

精彩评论

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