Create a Material Design-style Android app-define the shadow and cropping view, materialandroid

Source: Internet
Author: User

Create a Material Design-style Android app-define the shadow and cropping view, materialandroid

I have previously written about using the topic and ListView, CardView, and Material Design Styles. Both of them can be backward compatible through the support library. The shadow and view cropping to be written today are not backward compatible. Please note.

Material Design introduces the depth element to the user interface element. It deeply helps users understand the important associations between various elements and help users focus on their tasks.

The height of a view (elevation) is expressed by the Z attribute and determined by its shadow: A view with a higher z value projects a larger shadow. Views only have shadows on the plane where Z = 0 is projected; they do not have shadows on other views placed below and above the plane where z = 0 is projected.

A view with a higher Z value blocks a view with a lower Z value. In any case, the Z value does not affect the View size.

It is highly useful. When performing some actions, you can create an animation to raise the component.

Assign height to a view

The Z value of a View has two components,Elevation (height)AndTranslation). Elevation is a static part, and translation is used for Animation:

Z = elevation + translationZ


View shadows of different heights

Set evelation usage in the layout Fileandroid:elevation, Used in the codeView.setElevation()Method.
Set the translation of a View and use the View. setTranslationZ () method.

New MethodViewPropertyAnimator.z()AndViewPropertyAnimator.translationZ()It makes it easier for you to change the height of a view. For more information, see the 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 use StateListAnimator to define these files in an xml file. It is especially suitable for animations executed when the status changes, such as clicking a button. For more information, see the animation view status change, which will be discussed in the animation section next time.
The Z value is measured in the same unit as the X and Y values.

Custom view shadows and outlines

The background boundary of the view determines the default shape of the shadow. Outlines represent the shape of the image object and determine the ripple of the touch feedback area.

Let's look at this view and 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 the background drawable is used as the outline of the view, the view emits a rounded corner shadow. Provides a custom profile that can overwrite the shape of the default view shadow.

Customize an outline in your own code:

1. inherit the ViewOutlineProvider class
2. Override the getOutline () method.
3. Set the outline in the View and use the View. setOutlineProvider () method.

You can create an elliptical and rounded rectangular contour using methods in the OutLine class. The default outline provider of a view generates an outline based on The View background. You can set the outline provider of the view to null to prevent shadow casting.

Cropping View

The cropping view function makes it easier for you to change the view shape. You can crop a view to be consistent with other design elements or change it to a shape to respond to user input. You can crop the outline of a view.View.setClipToOutLine()Method, orandroid:clipToOutlineAttribute. Only the rectangle and rounded rectangle are supported. The circle contour can be cropped.Outline.canClip()Method to check whether cropping is supported.

Crop a view to a drawable shape, set drawable as the view background (to display the view on it), and callView.setClipToOutline()Method.

Cropping a view is a costly operation. Do not use shape animation when cropping a view. To achieve this Effect, use the Reveal Effect animation (next section ).

Summary

As you can see above, it is easy to set the shadow:

  1. Set the value of eleavation.
  2. Add a background or set an outline.

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

Original article address: Workshop.


In android, when the canvas required by the child view is larger than the parent view, how can the excess part not be cropped?

Follow up
 
How to Create a PPT tutorial

Basic ppt knowledge and usage skills
PowerPoint is one of the main tools for teachers to make courseware. The following describes some basic ppt knowledge and tips for beginners.
I. Start and exit the PPT
1. Open method:
Method 1: Click the start button on the desktop and select program> Microsoft Office PowerPoint 2003 ". This is a standard startup method.
Method 2: double-click the desktop shortcut icon "Microsoft Office PowerPoint ....". This is a quick start method.
2. Exit method:
Method 1: click "X" in the upper-right corner of the window ".
Method 2: Close all presentations and exit the PPT
Click "file"> "exit" in the menu ".
Ii. Slide layout Selection
Select and click the expected layout in the right-side slide layout. In the actual courseware production process, the instructor hopes to design the template by himself. In this case, the "blank" layout in the "content layout" can be used for free creation.
Iii. Operations on slides
The simple process of designing an application PPT is: first create several slides in sequence, and then insert the desired objects on these slides, finally, play the slides from start to end (you can create a hyperlink for the object to change the playback sequence of the slides ).
Slides are at the core of the PPT design. Operations on slides include selecting, inserting, deleting, moving, and copying slides. These operations can be performed under "normal view, you can also click "slide View. The following uses the "normal view" as an example to describe various operations on slides. Under "normal view", the left side of the main PPT window is "outline editing window", which includes "outline" and "slides". Click the "slides" tab, the thumbnails of all slides in the current presentation are displayed. The sequence number before each slide indicates the sequence in which the slides are played. You can drag the scroll bar to display the remaining slides, operations on slides are performed in this area.

1. Slide Selection
Many operations require you to select a slide first. You can select one slide (select one slide) or multiple slides (select multiple slides at the same time ), multiple selections include consecutive multiple selections (multiple adjacent slides) and non-consecutive multiple selections (multiple adjacent slides). The procedure is as follows:
(1) single choice: Click the slide thumbnail to be selected (for example, the thumbnail at the end of the slide in the yellow box on the left). The thumbnail displays a blue frame, which is called the "current slide ".
(2) multiple consecutive selections: Click the First of multiple adjacent slides, hold down the Shift key, and click the last one.
(3) multiple consecutive selections: click a slide, press Ctrl, and click the slide to be selected.
2. Slide insertion
When you feel that the slides are insufficient during the design process, you need to insert the slides. There are four ways to insert a slide:
Method 1: select a slide, click "insert"> "new slide" in the menu, and a new slide is inserted after the current slide.
Method 2: select a slide and click the "new slide" button on the toolbar. A new slide is inserted after the current slide.
Method 3: Right-click a slide and select "new slide" in the pop-up menu. A new slide is inserted after the slide.
Method 4: select a slide first, and press "enter". A new slide is inserted after the current slide.
3. Slide Deletion
If a slide is no longer useful, you need to delete the slide. There are three ways to delete a slide:
Method 1: select to Delete the slide (you can select multiple slides), press the "Delete" key on the disk, and the selected slides are deleted. The remaining slides are moved up sequentially.
Method 2: select to delete a slide (you can select multiple slides), select "edit"> "cut" from the menu, delete the selected slides, and move the remaining slides up sequentially.
Method 3: Right-click the slides you want to delete (multiple slides can be selected), select the "delete slides" option in the pop-up menu, and select the slides to be selected.

Related Article

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.