


Yesterday we introduced the basic usage of Animation. How do you guys understand? If you haven’t learned about Animation yet, you can read this blog
Introduction to android animation - Animation to achieve loading animation effect
Although the four built-in animations in Android can be combined using AnimationSet Operation, but these combinations are often not enough in specific situations. Just like view, we can customize animation effects.
The effect we want to create today is to imitate QQ’s shaking effect. As usual, let’s take a look at today’s renderings first:
Customized animation The implementation method is to inherit the Animation class and rewrite the applyTransformation() method
public class CustomAnimation extends Animation { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { t.getMatrix().setTranslate((float)Math.sin(interpolatedTime*50)*20,0); super.applyTransformation(interpolatedTime, t); }}
You can see that the applyTransformation() method has two parameters. The first parameter interpolatedTime represents a 0-1 gradually The increased float and t represent the changes required by the view, such as t.setAlpha(); t.setTranslate(); as the names suggest, these two methods are responsible for transparency changes and displacement changes.
So our goal today is to achieve a shaking effect. The idea is as follows: The view is first displaced to the left, and then to the right. The coordinates are (0-n,0) --->(0 n,n). The change of one positive and one negative requires the use of our trigonometric functions. So here t.setTranslate(Math.sin()).
Basically our custom animation is complete. Next, get the current layout under MainActivity and add animation effects to it
public class MainActivity extends ActionBarActivity { private Button mButton; private RelativeLayout mRelativeLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mButton = (Button) findViewById(R.id.shake); mRelativeLayout = (RelativeLayout) findViewById(R.id.relativelayout); final CustomAnimation ca = new CustomAnimation(); ca.setDuration(1000); mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mRelativeLayout.startAnimation(ca); } }); }}
That’s it! If you like my blog, please like it
Source code download
Copyright statement: This article is an original article by the blogger. You are welcome to reprint after indicating the source.

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools
