Create material Design-style Android apps-define shadows and crop views

Source: Internet
Author: User

Previously written by applying themes and using the ListView, CardView, applying the material design style, both can be backwards-compatible through the support library. The shadows and views to be written today are cropped and cannot be backwards-compatible, please note.

? Material Design introduces the element of depth to the user interface element. Depth helps users understand the important associations between elements and helps users focus on the tasks they have in hand.

The height of the view (elevation), represented by the Z-property, is determined by his shadow: a higher-Z view casts a larger shadow. Views only shadow shadows on z=0 planes, and they do not shadow shadows on other views that are placed above and above the z=0 plane.

Views with higher Z-values block lower Z-values. In any case, the Z-value does not affect the size of the view.

Height is also useful when creating animations to make a component rise when performing some action.

Assign a height to a view

The z-value of a view has two components,elevation (height) and translation (panning). Elevation is a static part, translation for animation:

Z = elevation + Translationz

Shading of views of different heights

Set evelation in the layout file android:elevation , using methods in your code View.setElevation() .
Set the panning of a view using the View.settranslationz () method.

New methods ViewPropertyAnimator.z() and ViewPropertyAnimator.translationZ() can make it easier for you to change the height of the view. For more information, see Viewpropertyanimator API documentation http://developer.android.com/reference/android/view/ViewPropertyAnimator.html. and property Animation Development Guide: http://developer.android.com/guide/topics/graphics/prop-animation.html.

You can also define these files in an XML file using the Statelistanimator method. Ideal for animations that are executed when the state changes, such as when a user clicks a button. For more information, see Animation View state changes, next time in the animation section.
The z-values are measured in units of the same value as the X, y values.

Customizing View Shadows and Outlines

The background boundary of the view determines the default shape of the shadow. The contour (outlines) represents the shape of the graphic object and determines the ripple of the touch feedback area.

To see this view, define a background drawable:

<textview    android:id= "@+id/myview" ...    android:elevation= "2DP"    android:background= "@drawable/myrect"/>

The background is a rounded rectangle

<!--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>

When this background drawable as the outline of the view, the view casts a rounded shadow. Provides a custom outline that can override the default view Shadow shape.

Customize a profile in your own code:

1. Inheriting the Viewoutlineprovider class
2. Overriding the Getoutline () method
3. Set the outline in the view, using the View.setoutlineprovider () method

You can create ellipses and rounded rectangle outlines using methods in the outline class. The default outline provider of the view generates outlines based on the background of the view. You can set the outline provider of the view to NULL to prevent casting shadows.

Crop view

The Crop view feature allows you to change the shape of the view more easily. You can crop the view in order to be consistent with other design elements, or to change the shape to respond to the user's input. You can crop the outline of a view using a View.setClipToOutLine() method, or a android:clipToOutline property. Only rectangles, rounded rectangles, and circle outlines are clipped, and you can use Outline.canClip() methods to detect whether the support is clipped.

Crop the view to a drawable shape, set drawable as the background of the view (let the view appear on it), and call the View.setClipToOutline() method.

Cropping a view is an expensive operation and does not use shape animation when cropping the view. To achieve this effect, use the Reveal Effect animation (the next section).

Summarize

As you can see above, setting the shadow is simple:

    1. Sets the Eleavation value.
    2. Add a background or set a outline.

Reference: http://developer.android.com/training/material/shadows-clipping.html

Original address: http://blog.isming.me/2014/10/26/creating-app-with-material-design-three-shadows/, reproduced please indicate the source.

Create material Design-style Android apps-define shadows and crop views

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.