Android 5.x new features elevation (shading), tinting (shading) and clipping (clipping)

Source: Internet
Author: User

Fast New Year, the company has nothing to do, oneself also idle down, day by day to stay really boring, free to do their own research and study of Google I/o 2014 released Material design, humanized style, rich color, make human machine interaction more perfect. Chinese study Address http://wiki.jikexueyuan.com/project/material-design/(this seems to be a geek college translator), of course, if your citation OK, you can also go to the official English document HTTP/s www.google.com/design/spec/material-design/.

1. Shadow and Height--elevation

Typically, Android's view design takes x,y2 directions, but after 5.x Google introduces a Z attribute, let's take a look at the official:

As you can see, the picture above looks like a shadow, as if 2 pictures are not a height, and his side view, just can explain, how can achieve this effect, we can re-layout space inside Add a elevation attribute, (easy to use)

1<TextView2Android:layout_width="100DP"3android:layout_height="100DP"4android:layout_margin="10DP"5android:elevation="1DP" 6Android:background="@mipmap/banner_pingan_default"/>

Of course, we can also use code to implement

View.settranslationz (+);

2.tinting

After Android 5.X also introduced a property called tint, meaning "coloring", there are two forms:

1, android:backgroundtint= "" 2, Android:tint= ""

Let's take a look at one: this is mainly defined in the XML file tint and TintMode2 attributes, of which Tintmode has 6.

Tintmode mainly change the pattern of our coloring!!!! The default mode of the general situation is src_in;

In order the first one is the original picture, the rest of the Tintmode properties are set to: Add,multiply,screen,src_atop,src_in,src_over,

We can see that the main is to the picture with a layer of mask color.

  

Of course we also know that this is a new feature above 5.x, what if we want him to support the lower version? Goolge of course, this time we need to introduce the Support-v7jar package,

We need it. The required control is defined as: Android.support.v7.widget.AppCompat ...

We take TextView as an example:

1 <android.support.v7.widget.AppCompatTextView2     android:id="@+id /t1"3     android:layout_width="match_parent"4      android:layout_height="50dp"5     android:text=" Test " />

But notice, at this point, we can't define in the layout what we need to set in the code.

1 viewcompat.setsupportbackgroundtintlist (colorstatelist tint); 2 viewcompat.setsupportbackgroundtintmode (Porterduff.mode tintmode);

Note : We can see that the first line requires a parameter of type colorstatelist , and this time we can use getresource (). Getcolorstatelist ( R.color. Color value), to obtain

3.clipping

In half, we all change the shape of a view, a common example of a textview with rounded corners, and we typically use shape resources to make a background of this kind of textview. For example

So how do we go about implementing such a style, rather than using shape, it's simple, let's just look at how the XML file is laid out

1<TextView2Android:id="@+id/tv1"3Android:layout_width="200DP"4android:layout_height="50DP"5android:elevation="1DP"6android:text="Register"7Android:textsize="19SP"8android:gravity="Center"9Android:textcolor="@color/colorprimarydark"Tenandroid:layout_margin="20DP"/>

As can be seen, we just added a elevation property, set to 1DP Shadow, the main figure is to implement in the code, we see how to achieve

 //  get outline, we need to use viewoutlineprovider< /span> viewoutlineprovider viewoutlineprovider=new   Viewoutlineprovider () {@Override  public  void   Getoutline (view view, Outline Outline) { //  Modify the outline shape, here is set to set the left upper right, and radius  outline.setroundrect (
    
     0 
    , 0 , View.getwidth (), View.getheight (), 30             );        }        };         //will need control   override set Shape  Tv1.setoutlineprovider (Viewoutlineprovider); 

So simple, in fact, is to use the shadow to give people a visual illusion.

Android 5.x new features elevation (shading), tinting (shading) and clipping (clipping)

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.