how to align text vertically center in android

后端 未结 5 1907
终归单人心
终归单人心 2021-02-02 06:14

I have arabic text, therefore I set gravity to right in order to start text from right side. Text starts from right now. But another issue is text starts to render from the top

5条回答
  •  抹茶落季
    2021-02-02 06:24

    Your TextView Attributes need to be something like,

    
    

    Now, Description why these need to be done,

     android:layout_width="match_parent"
     android:layout_height="match_parent"
    

    Makes your TextView to match_parent or fill_parent if You don't want to be it like, match_parent you have to give some specified values to layout_height so it get space for vertical center gravity. android:layout_width="match_parent" necessary because it align your TextView in Right side so you can recognize respect to Parent Layout of TextView.

    Now, its about android:gravity which makes the content of Your TextView alignment. android:layout_gravity makes alignment of TextView respected to its Parent Layout.

    Update:

    As below comment says use fill_parent instead of match_parent. (Problem in some device.)

提交回复
热议问题