Reprint Please specify source: http://blog.csdn.net/bbld_/article/details/40539131
Material Design introduces a deep UI element. Drill down to help users understand the relative importance of each element and focus on what is being done at hand.
A view (control), the elevation represented by the Z property (elevation), determines the size of its shadow: a higher Z-worthy view has a larger shadow. Views only cast shadows on the z=0 plane, and they are not projected under them and in other views of the z=0 plane above them.
A view with a higher Z-value (the control) blocks the lower Z-values. However, the z-value of a view does not affect the size of the view.
Elevation is useful for creating animations when a control temporarily crosses a flat view to perform certain operations.
Specify elevation in your view (control) (ElevatioN)
The z-value of a view consists of two parts: elevation and transformation. Elevations are static components, and transformations are used for animations.
Z = Elevation +translationz
Figure one: Shadow of a View control with different elevation attribute values
To set the elevation of a view control in a layout, use the android:elevation property. To set the elevation of the view in code, use the view.setelevation () method.
To set a transform for a view (translation), use the View.settranslationz () method.
The new Viewpropertyanimator.z () and Viewpropertyanimator.translationz () methods allow you to easily make changes to the view elevation. For more information, see the developer guidelines for Viewpropertyanimator API documentation and propertyanimation (property animation) .
You can also use statelistanimator to specify these animations declaratively. This is particularly useful for situations where the animation is triggered when the state changes, such as when a user presses a button. For more information, see Animate View State changes(defining Custom Animations)(not updated).
Z-values are measured in the same (graphic) unit as the X and Y values.
Customizing View Shadows and Outlines
The background drawing of a view determines the default shape of its shadow. The contour represents the outer shape of the drawing object and limits the ripple (Ripple) area of the touch feedback.
Take a look at the following view (TextView), which defines the background of the picture resource:
<textview android:id= "@+id/myview" ... android:elevation= "2DP" android:background= "@drawable/myrect"/>
The background resource is 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>
The view control masks a shadow with rounded corners, because the background picture resource defines the outline of the view. Provides a custom outline to override the default shape of the view shadow.
Customize the outline of the view in your code:
1. Inheriting the Viewoutlineprovider class
2. Overriding the Getoutline () getoutline () method
3. Use the View.setoutlineprovider () method to assign a new outline to your view
With the methods in the Outline class, you can create oval and rectangular shapes with rounded corners. The default contour provider (provider) for a view obtains its outline from the background of the view. To prevent shading of the view, set its outline provider to null.
Crop view
Cropping the view allows you to easily change the shape of the view. You can use other design elements to crop the view for consistency or to change the shape of the view in response to user input. You can use the view.setcliptooutline () method or use the android:cliptooutline property to crop the view's own outline shape. Only the outlines of rectangles, circles, rounded rectangles support clipping, which is determined by the Outline.canclip () method.
In order to crop the view to get the image resource for the specified shape, set the background resource for the view (as shown above) and call the View.setcliptooutline method.
Cropping a view is a costly operation, so do not make the shape look vivid and cut the view to achieve this effect you should use Reveal Effect (defining Custom Animations) ( not updated ) Animation.
Demo is relatively simple, on the above two pieces of code is not posted up.
Android meterial design-defining Shadows and Clipping views (define shadow and crop view)-(iv)