How to show shadow around the linearlayout in Android?

前端 未结 13 2559
名媛妹妹
名媛妹妹 2020-11-27 10:51

How can I show shadow for my linear layout. I want white colored rounded background with shadow around the linearlayout. I have done this so far.



        
13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 11:11

    Well, this is easy to achieve .

    Just build a GradientDrawable that comes from black and goes to a transparent color, than use parent relationship to place your shape close to the View that you want to have a shadow, then you just have to give any values to height or width .

    Here is an example, this file have to be created inside res/drawable , I name it as shadow.xml :

    
    
    
         
        
    
    
    

    Place the following code above from a LinearLayout , for example, set the android:layout_width and android:layout_height to fill_parent and 2.3dp, you'll have a nice shadow effect on your LinearLayout .

    
    
    

    Note 1: If you increase android:layout_height more shadow will be shown .

    Note 2: Use android:layout_above="@+id/id_from_your_LinearLayout" attribute if you are placing this code inside a RelativeLayout, otherwise ignore it.

    Hope it help someone.

提交回复
热议问题