Android: how to have a centered background image in a view

前端 未结 1 2019
感动是毒
感动是毒 2021-01-05 16:45

I\'d like to use a small (icon size) image as the background for my view, but it gets stretched to fill all the view.

Any solution (including some way to place a vie

1条回答
  •  北海茫月
    2021-01-05 17:20

    You have two choices:

    1. Make the image bigger. Specifically, add a single black line all around its edges, then use the tools/draw9patch tool to make that black line the 'stretchable' part. When the image is scaled up to the background, your original icon will not be stretched.

    2. Give up on the android:background and use a top level RelativeLayout instead. This should work

    
        
        
        
            
            
        
    
    

    Hope this helps

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