Android5.0 new Features--button click Effect Animation (ripple effect)

Source: Internet
Author: User
Android5.0 Material Design Animation effect rippledrawable Ripple effect

The ripple effect is a new feature after Android5.0. For compatibility, it is recommended that you create a new DRAWABLE-V21 folder to hold the Rippledrawable,drawable folder to fit the appropriate picture. (Here you can install a androidselector plug-in, the specific can refer to the third part of 53102615)

Ripple animation is mainly used for ripple tags. , where the ripple node must be set to the Color property. The color of the setting of the root node here is the ripple color of the ripple effect. The drawable of the child node's item setting is the background of the ripple effect (which can also be thought of as the extent of the ripple effect).

I have 4 different effects depending on the scene. Don't say a word more first.

1, only ripple node, no item child node. As can be seen, the ripple effect of the diffusion range is not limited. Has spread to the parent control.

1 <? XML version= "1.0" encoding= "Utf-8" ?> 2 <  xmlns:android= "Http://schemas.android.com/apk/res/android"3     Android:color= "@color/colorbtn">4</Ripple >

2. Contains a single item node. By, you can see that the control shows the background color of the setting. The scope of the ripple effect has been controlled.

<?XML version= "1.0" encoding= "Utf-8"?><Ripplexmlns:android= "Http://schemas.android.com/apk/res/android"Android:color= "@color/colorbtn">    <!--Display the default drawable -    <Itemandroid:drawable= "@color/colorwhite" /></Ripple>

3, the second situation has been in line with most of the scene. But with some of the visual effects now changing, the background may be transparent as long as the ripple effect is present. Set the item node with ID mask, which only plays a ripple effect, does not display the set of drawable

 <?  xml version= "1.0" encoding= "Utf-8"  ?>  <  ripple  xmlns:android  = "Http://schemas.android.com/apk/res/android"   Android:color  = "@color/colorbtn"     >  <  item  android:id  = "@android: Id/mask"   android:drawable  = "@color/colorprimary"  />  </ ripple  >  

4, the fourth kind actually and the second kind of effect is the same. Personal feelings are no different. Want to know the Daniel for guidance

<?XML version= "1.0" encoding= "Utf-8"?><Ripplexmlns:android= "Http://schemas.android.com/apk/res/android"Android:color= "@color/colorbtn">    <!--Display the default drawable -    <Itemandroid:drawable= "@color/colorwhite" />    <ItemAndroid:id= "@android: Id/mask"android:drawable= "@color/coloraccent"/></Ripple>

My layout file:

<?XML version= "1.0" encoding= "Utf-8"?><Android. Support.constraint.ConstraintLayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:app= "Http://schemas.android.com/apk/res-auto"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.gaosiedu.android50.MainActivity">    <ButtonAndroid:id= "@+id/btn_touch_no"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_marginend= "8DP"Android:layout_marginstart= "8DP"Android:layout_margintop= "48DP"Android:background= "@drawable/ripple_item_no"Android:text= "No Item effect"app:layout_constraintend_toendof= "Parent"App:layout_constraintstart_tostartof= "Parent"App:layout_constrainttop_totopof= "Parent" />    <ButtonAndroid:id= "@+id/btn_touch_single"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_marginstart= "8DP"Android:layout_margintop= "44DP"Android:background= "@drawable/ripple_item_single"Android:text= "Have item effect"app:layout_constraintend_toendof= "@+id/btn_touch_no"App:layout_constraintstart_tostartof= "@+id/btn_touch_no"App:layout_constrainttop_tobottomof= "@+id/btn_touch_no" />    <ButtonAndroid:id= "@+id/btn_touch_mask"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_margintop= "40DP"Android:background= "@drawable/ripple_item_mask"Android:text= "Item contains mask effect"app:layout_constraintend_toendof= "@+id/btn_touch_single"App:layout_constraintstart_tostartof= "@+id/btn_touch_single"App:layout_constrainttop_tobottomof= "@+id/btn_touch_single" />    <ButtonAndroid:id= "@+id/btn_touch_double"Android:layout_width= "360DP"Android:layout_height= "Wrap_content"Android:layout_marginend= "8DP"Android:layout_margintop= "40DP"Android:background= "@drawable/ripple_item_double"Android:text= "2 Item with mask effect"app:layout_constraintend_toendof= "@+id/btn_touch_mask"App:layout_constrainthorizontal_bias= "0.0"App:layout_constraintstart_tostartof= "@+id/btn_touch_mask"App:layout_constrainttop_tobottomof= "@+id/btn_touch_mask" /></Android.support.constraint.ConstraintLayout>

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.