Android - Set a border around an ImageView

前端 未结 9 1524
旧时难觅i
旧时难觅i 2021-02-06 23:50

I have a cell with a fixed width and height, let it be 100x100px. Inside that cell I want to display an ImageView with a border around.
My first idea was to put

9条回答
  •  Happy的楠姐
    2021-02-07 00:12

    If the images are variable in size then you'll always get that effect. I guess you need to set a fixed size for the ImageView and give it a set background colour - from the look of your example black would make sense. Wrap the imageview in a FrameLayout or just a view with a yellow background and 1px padding.

    EDIT


    I had a think about this and my answer didn't feel right so...

    If you set each ImageView with a fixed size, padding and margin. and then set the background colour as required you can get the effect you want.

    
    
    
    
            
    
            
    
    
    

    In the screenshot both displayed images are less than 100px in width and different heights.

    example

    This doesn't handle images with transparent backgrounds as then the (in this case) yellow green colour shows through. You could solve this by wrapping each ImageView in a FrameLayout. Making the ImageView background black and setting the FrameLayout to WrapContent with the required padding (I think)

提交回复
热议问题