Android TextView Text not getting wrapped

前端 未结 24 1705
时光说笑
时光说笑 2020-11-27 02:51

Can anyone tell me what\'s going wrong with the text? Text longer than one line doesn\'t wrap to the next line but goes beyond the screen.

Following is the code:

24条回答
  •  半阙折子戏
    2020-11-27 03:25

    I'm an Android (and GUI) beginner, but have lots of experience with software. I've gone through a few of the tutorials, and this is my understanding:

    layout_width and layout_height are attributes of the TextView. They are instructions for how the TextView should shape itself, they aren't referring to how to handle the content within the TextView.

    If you use "fill_parent", you are saying that the TextView should shape itself relative to it's parent view, it should fill it.

    If you use "wrap_content", you are saying that you should ignore the parent view, and let the contents of the TextView define it's shape.

    I think this is the confusing point. "wrap_content" isn't telling the TextView how to manage it's contents (to wrap the lines), it's telling it that it should shape itself relative to it's contents. In this case, with no new line characters, it shapes itself so that all the text is on a single line (which unfortunately is overflowing the parent).

    I think you want it to fill the parent horizontally, and to wrap it's contents vertically.

提交回复
热议问题