Android enlarge center color with gradient

前端 未结 1 2049
[愿得一人]
[愿得一人] 2021-02-10 02:09

I can not enlarge the width of a centeral color with a gradient.
The goal is:

Larger center with some color, and transparent on sides.

Usage:



        
1条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-10 02:23

    I hope this is what you had in mind. I am using layer-list. I have used "@color/colorAccent" for either end. Change it to "#0FFF" to get a transparent color, which was required in the question.

    
        
            
                
                
            
        
        
            
                
                
            
        
    
    

    Play around with the android:centerX attributes till you get what you want.

    OUTPUT

    This is what the drawable preview looks like with centerX at 10% and 80%

    now with centerX at 60% and 40%

    EDIT

    To get the same effect in a layout that uses match_parent as the layout_width parameter, split the gradient into two drawables and set it as background for 2 different ImageViews or FrameLayouts

    left_gradient.xml

    
        
    
    

    right_gradient.xml

    
        
    
    

    In your Layout xml file

    
        
        
    
    

    Like with the previous case, tweak around with the values in android:centerX of both the gradient files to get the desired result

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