Can´t center textview´s text vertically

前端 未结 7 1780

[Solved] I had to add android:fillViewport=\"true\" to the ScrollView, that fixed the problem with the text not centering vertically.

I know this has been

7条回答
  •  渐次进展
    2021-02-09 17:02

    android:gravity specifies how a parent will position its children. In this case the parent is the TextView and the child is the actual text within that view. If the TextView (parent) is not wider than the text (child) then gravity will have no effect.

    The android:gravity docs for reference:

    Specifies how to align the text by the view's x- and/or y-axis when the text is smaller than the view.

    Set the width of your TextView like this:

    android:layout_width="match_parent"
    

    That should cause the Text to get centered vertically.

提交回复
热议问题