The method of realizing ImageView picture parabola animation effect by Android programming _android

Source: Internet
Author: User
Tags gety

This article illustrates the method of implementing the parabolic animation effect of ImageView picture by Android programming. Share to everyone for your reference, specific as follows:

To achieve a parabolic animation, you must know the parabolic equation, which is the function of mathematics, if the parabola of the graph:

According to the equation of the parabola, it is known that any three points can be determined by a parabola, annotated by a known parabolic line.

The equation is y = ax²+ bx + c; Suppose the A1 coordinates are (0,0), the A2 coordinates are (300,0), and the A3 coordinates are (150,300); the equation of the parabolic line is y = -1/75 x²+ 4x; By this equation, we can determine the relationship between the parabola X and Y, and the following The feeling is simple.

In the new API, there are objectanimator animations, and in this animation we can do something we want. About the use of objectanimator, everyone to find information to see it: The following directly to the source code:

Move animation in 300 steps final int count = 300; /** * ImageView * @param imageview/private void Startanimation (final ImageView ImageView) of the image to start animation {KEYFR 
  ame[] keyframes = new Keyframe[count]; 
  Final float Keystep = 1f/(float) count; 
  float key = Keystep; 
   for (int i = 0; i < count; ++i) {Keyframes[i] = keyframe.offloat (key, i + 1); 
  Key + + Keystep; 
  } Propertyvaluesholder PVHX = Propertyvaluesholder.ofkeyframe ("Translationx", keyframes); 
  key = Keystep; 
   for (int i = 0; i < count; ++i) {Keyframes[i] = keyframe.offloat (key,-gety (i + 1)); 
  Key + + Keystep; 
  } Propertyvaluesholder pvhy = Propertyvaluesholder.ofkeyframe ("Translationy", keyframes); 
  Objectanimator yxbouncer = Objectanimator.ofpropertyvaluesholder (ImageView, Pvhy, PVHX). setDuration (1500); 
  Yxbouncer.setinterpolator (New Bounceinterpolator ()); 
Yxbouncer.start (); 
Final float a = -1f/75f; /** * Here is a parabolic equation calculated from three coordinate points {(0,0), (300,0), (150,300)} * @param x * @retUrn */private float GetY (float x) {return a * x * x + 4 * x; }

The call is very simple: startanimation (ImageView) can, Propertyvaluesholder, and so on their own look at the information.

An algorithm for solving the parabolic equation with the known parabola three points is attached:

Package com.freesonfish;  public class Parabolaalgorithm {public static void main (string[] args) {final float[][] points = {6, 15}, {15, 
  70}, {40, 60}}; 
 Calculate (points);  /** * a = (Y1 * (x2-x3) + y2 * (x3-x1) + y3 * (X1-X2))/(X1 * X1 * (x2-x3) + x2 * x2 * (x3-x1) + x3 
  * X3 * (X1-X2)) * b = (y1-y2)/(X1-X2)-A * (x1 + x2); 
  * c = y1-(x1 * x1) * a-x1 * b; 
  * * private static void calculate (float[][] points) {float x1 = points[0][0]; 
  float y1 = points[0][1]; 
  float x2 = points[1][0]; 
  float y2 = points[1][1]; 
  Float x3 = points[2][0]; 
  float y3 = points[2][1]; Final float a = (Y1 * (x2-x3) + y2 * (x3-x1) + y3 * (X1-X2))/(X1 * x1 * (X2-X3) + x2 * x2 * (x3-x1) + x3 
  * X3 * (X1-X2)); 
  Final float B = (y1-y2)/(X1-X2)-A * (x1 + x2); 
  Final float c = y1-(x1 * x1) * a-x1 * b; 
 System.out.println ("-a->" + A + "b->" +b + "c->" +c);

 } 
}

I hope this article will help you with your Android programming.

Related Article

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.