How do I make a drawable from multiple images?

后端 未结 1 810
谎友^
谎友^ 2021-02-07 03:47

I have three 9-patch PNG\'s which together make up the background for a button (left side, middle, right side). I would like to combine these three images together in a drawabl

1条回答
  •  不知归路
    2021-02-07 04:15

    After some trial-and-error, I was able to solve the problem in a satisfactory way. I simply implemented a Layer-List drawable as follows:

    
    
        
        
        
    
    

    Where the 26px values are the width of the two button side images in pixels.

    To use this drawable, simply call it like any other drawable:

    
    

    This works exactly how you would expect it to, with the middle expanding as normal to fit the desired width, and all three images expanding to fit the desired height. I hope others can benefit from this!

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