Android: Center an image

前端 未结 13 1032
Happy的楠姐
Happy的楠姐 2020-12-07 17:38

I\'ve got a linear layout and an image...





        
相关标签:
13条回答
  • 2020-12-07 18:26

    Technically both answers above are correct, but since you are setting your ImageView to fill_parent instead of wrap_content, the image within is not centered, but the ImageView itself is.

    Give your ImageView the attributes:

    android:scaleType="centerInside"
    android:gravity="center"
    

    The scaleType is really only necessary in this case if the image exceeds the size of the ImageView. You may also want different scaleTypes. In conclusion, android:gravity is what you're looking for in this case, but if your ImageView is set to wrap_content, you should set the ImageView's gravity (android:layout_gravity) to be centered within the parent.

    0 讨论(0)
提交回复
热议问题