Android 5.x features Overview Four

Source: Internet
Author: User

In the last section, we talked about Palatte and its characteristics, here we introduce another feature view and shadow of Android 5.x.

In the first section, we mentioned that the Material design is a big feature is flattening, if the flat of iOS is too advanced, so many people do not have time to change from the object to flat, then Material design is more than the flat effect of iOS more grounded gas. Simulate a dynamic and beautiful bold visual effect by demonstrating the material effects in your life, using shadows and light appropriately, and with smooth, realistic animations.

  Shadow effect

Previous Android View typically had only two coordinates--x and Y, while in Android 5.X, Google added a new coordinate--z, which corresponds to a height change in the vertical direction. Believe that through, you can quickly understand the meaning of Z.

In Android 5.X, the Z-value of View consists of two parts, elevation and Translationz (both of which are android5.x newly introduced properties). Elevation are static members, Translationz can be used in code to animate, and their relationships are as follows.

1. Android:elevation sets the height of the component "floating", to be sad too setting this property allows the component to render a 3D effect.

2. Android:translationz sets the displacement of the component in the Z-direction (vertical screen orientation).

The z-axis distance is z = elevation + Translationz, we can set the value of elevation in the XML layout file, the corresponding source code is as follows:

  

android:elevation= "XXDP"

The following example shows the difference between the different view heights, as shown in the XML code:

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Tools:context=". Mainactivity " >    <TextViewAndroid:layout_width= "100DP"Android:layout_height= "100DP"Android:layout_margin= "10DP"Android:background= "#00ff00" />    <TextViewAndroid:layout_width= "100DP"Android:layout_height= "100DP"Android:layout_margin= "10DP"Android:background= "#00ff00"android:elevation= "2DP" />    <TextViewAndroid:layout_width= "100DP"Android:layout_height= "100DP"Android:layout_margin= "10DP"Android:background= "#00ff00"android:elevation= "10DP" /></LinearLayout>

The corresponding following:

The coin has both sides, similarly, Android can have XML settings properties, and of course you can set the view height with Java code, the corresponding Java code is as follows:

View.settranslationz (XXX);

Of course, we also often use property animations to add an animation effect to the view height change, as shown in the code below.

if (flag) {view.animate (). Translationz (falseElse  {view.animate ( ). Translationz (0true;}

This is an introduction to the shadow effect in material design.

Android 5.x features Overview Four

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.