Question

If I try to center the current view vertically within its parent. Which one should I use?

I saw TextViews use gravity="center_vertical" and ImageViews uselayout_centerVertical="true".

I am not sure why?

Was it helpful?

Solution

In textview , gravity="center_vertical" means the content in the textview will be center and vertical . you can only see the alignment of text if textview is fill_parent if its wrap_content then there will be no place for content to have alignment.If you use layout_gravity here and width and height to wrap_content then it will place the textview in the center _vertical of the parent layout.

In imageview ,layout_centerVertical="true". means place iamge and in center and vertical in the parent layout of image (i.e the container of image).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top