Official website: https://developer.android.com/intl/zh-tw/training/material/shadows-clipping.html
Material design introduces a depth value to UI elements,depth helps users understand the relative importance of each element, focusing on the task at hand
The elevation value of each view, equivalent to the Z attribute, determines the size of the shadow: the larger the z, the larger the shadow.
Views are projected only on the plane of the z=0, and they are not projected on other views placed below them and above.
Views with higher Z-values block views with lower Z-values.
However, the z-value of a view does not affect the size of the view.
Elevation is useful for creating animations that do something when a component needs to be temporarily up to the view plane.
Assign elevation to Your views the Elevationz value specified in the views contains two components: Elevation and translation.elevation is a static ingredient,translation uses the animation :Z = elevation + Translationz
Set elevation in layout, using the android:elevation property . Set in code, using the View.setelevation () method.
Set the translationof a view, using the View.settranslationz () method.
Viewpropertyanimator.z () and Viewpropertyanimator.translationz () can make it easier for you to push the elevation of views.
You can also use a statelistanimator to specify how these animations are declared. This is especially useful when a state change triggers an animation , such as when the user presses a button.
Customize View Shadows and outlines custom view shadows and Outlines
The border of the view's back picture determines the default shape of the shadow. The contour represents the outer shape of a drawing object and the defined ripple area used for touch feedback .
Reference:
<textview Android:id="@+id/myview" ... android:elevation="2DP" Android:background="@drawable/myrect" />
A background image can be defined as a rectangle with rounded corners
<!--res/drawable/myrect.xml --<shape xmlns:android="Http://schemas.android.com/apk/res/android" Android:shape="Rectangle"> <solid Android:color="#42000000" /> <corners Android:radius="5DP" /></shape>
Because the background image defines the outline of the view (outline), the view will run a shadow with rounded corners. Provides a custom outline to override the default shadow shape for view. Custom outlines in code: • Inherit from Viewoutlineprovider rewrite getoutline () • Use View.setoutlineprovider () to assign a new profile
Using some methods of the outline class, create rounded rectangles andthe outline of the ellipse. The default outline provider contains the silhouette of the silhouette of the view. Block a view's projection, you can set the view's Ouline provider to NULL. Clip views Clipping
The trim view makes it easy to change the shape of the view. You can crop them uniformly to use other design elements, or change the shape of the view in response to user input. You can crop the external outline area of the view, using the View.setcliptooutline () or Android:cliptooutline property. Only rectangular, rounded, rounded rectangles support clipping of outlines, determined by the Outline.canclip () method. When you want to crop a shape into a picture, you need to set the picture as the background of the view and callView.setcliptooutline ().
cropping is a luxury operation, do not use dynamic graphics to crop. To achieve this effect, you can use animations to illustrate.
Android (lollipop/5.0) Material Design (iv) define shadows and crop view