Tips for defining shadows and cropping views for Android apps

Source: Internet
Author: User

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 using Android:elevation, using the View.setelevation () method in your code.

Set the panning of a view using the View.settranslationz () method.

The new Method Viewpropertyanimator.z () and Viewpropertyanimator.translationz () can make it easier for you to change the height of the view. For more information, see E mentor's Android app development video tutorial .

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:

The background is a rounded rectangle

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 the View.setcliptooutline () method, or the Android:cliptooutline property. Only rectangles, rounded rectangles, and circle outlines are clipped, and the Outline.canclip () method can be used 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:

Sets the Eleavation value.

Add a background or set a outline.

For more information on Android application development, please follow the e-mentor Network .

Tips for defining shadows and cropping views for Android apps

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.