I have an ImageView and TextView. I want to place the TextView below the image view but with the middle of the TextView aligned with the middle of the ImageView (along the horizontal axis). If the text in the TextView changes to something much larger or smaller, the middle of the text always needs to remain aligned with the middle of the ImageView. Is this possible in xml?
I have an ImageView and TextView . I want to place the TextView below
Share
Yes, you are simply looking to contain both elements in a vertical
LinearLayoutwhich hasandroid:gravityset tocenter_horizontal.Something like this:
Because the
TextView‘s width iswrap_content, setting its gravity shouldn’t be necessary. I would do it just for safety (and additionally, I may set the width tomatch_parentas well).