Android LinearLayout Gradient Background

前端 未结 10 1779
渐次进展
渐次进展 2020-12-02 04:20

I am having trouble applying a gradient background to a LinearLayout.

This should be relatively simple from what I have read but it just doesn\'t seem to work. For r

10条回答
  •  情深已故
    2020-12-02 04:48

    It is also possible to have the third color (center). And different kinds of shapes.

    For example in drawable/gradient.xml:

    
        
    
    

    This gives you black - gray - black (left to right) which is my favorite dark background atm.

    Remember to add gradient.xml as background in your layout xml:

    android:background="@drawable/gradient"
    

    It is also possible to rotate, with:

    angle="0"

    gives you a vertical line

    and with

    angle="90"

    gives you a horizontal line

    Possible angles are:

    0, 90, 180, 270.

    Also there are few different kind of shapes:

    android:shape="rectangle"

    Rounded shape:

    android:shape="oval"

    and problably a few more.

    Hope it helps, cheers!

提交回复
热议问题