Shape drawable in layer-list rendered incorrectly for APIs below 23

后端 未结 1 1212
花落未央
花落未央 2020-12-14 21:39

Yesterday, I\'ve switched to Android Studio version 2.1.3. Today, I\'ve re-opened one of my projects and tried to add some layer-list drawables for use with an ImageVi

1条回答
  •  别那么骄傲
    2020-12-14 22:07

    First of all, I'd like to thank @pskink for helping me to analyse the problem :)

    The xml in the question worked for API level 23+, because

    it is possible to set width and height right within the "item" tag

    like @android developer states in this SO post

    It did not work for lower versions, because there one needs to set width and height attributes for a ShapeDrawable using the size tag.

    I suppose Android needs the size to figure out how to scale the drawable (-> aspect ratio!) while taking into account the insets (top, left, right, bottom).

    And as is sometimes the case with malformed (for a specific API level) xml, Android failed silently and simply did not draw the shape.

    So the solution is:

    
        
            
                
            
        
        
            
                
                
            
        
    
    

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