search

Home  >  Q&A  >  body text

android - 布局时的边距如何从 view 的中心算起,而不是从左上角算起?

比如说有一张图片,我想让这张图片的中心距离父 view 的左边距是 x,图片大小不一定,这个操作在 Android 下该如何完成呢?

迷茫迷茫2772 days ago386

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-17 17:39:02

    Adjust the marginLeft value of imageView

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:39:02

    Move the original left margin to the left by half the width of the image, that is, subtract half the width of the image.


    If the image width is not sure, you can wait until it is confirmed and then dynamically change it.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:39:02

    If the poster's x is a fixed value, just use layout_marginLeft to get it. If it is a changing value, control it in the code.

    reply
    0
  • Cancelreply