Android Water Ripple Click Effect (Ripple Effect)

Source: Internet
Author: User

Android released the preview version of Android m last week. But presumably Android5.0 a lot of cool effects, most developers have not used, that is not to say the majority of users.

This article describes one of the cool effects in Android5.0, click on the Water Ripple Diffusion effect (Ripple Effect).

The implementation described below is a new API that calls Android5.0, not a custom implementation, so it supports devices in Android5.0.

If you want to be compatible with a low-system version, you need to create a new v21 (i.e. Android5.0) resource Directory.

Water ripple effect on rounded background (e.g.)

1. Define an XML with a normal rounded background;

Rounded_corners.xml

<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape= "Rectangle">    <SolidAndroid:color= "#FFFFFF" />    <CornersAndroid:radius= "4DP" /></Shape>

2. Here is the key,<ripple> is API21 only the new tag, is to achieve the effect of water ripple;

where <ripple android:color= "#FF21272B" .../> This is the color of the specified water ripple.

and <item/> Inside of things, we are very familiar with, is the ordinary definition of a rounded corner of the background.

Ripple_bg.xml:

<?XML version= "1.0" encoding= "Utf-8"?><Ripplexmlns:android= "Http://schemas.android.com/apk/res/android"Android:color= "#FF21272B">    <Item>        <ShapeAndroid:shape= "Rectangle">            <SolidAndroid:color= "#FFFFFF" />            <CornersAndroid:radius= "4DP" />        </Shape>    </Item>    <Itemandroid:drawable= "@drawable/rounded_corners" /></Ripple>

3. This is the layout XML of the activity;

Activity_main.xml

<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:gravity= "Center"android:orientation= "vertical"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity ">    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/hello_world" />    <ButtonAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:background= "@drawable/ripple_bg"Android:text= "@string/hello_world" /></LinearLayout>

Android Water Ripple Click Effect (Ripple Effect)

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.