I am an Android developer and I want to make custom views. I see people use formulas as…
- User
I am an Android developer and I want to make custom views. I see people use formulas as so: final float scale = (float) (2 * (2 * -StrictMath.atan(Math.abs(itemPositionToCenterDiff) + 1.0) / Math.PI + 1)); final float translateXGeneral = child.getMeasuredWidth() * (1 - scale) / 2f; translateX = Math.signum(itemPositionToCenterDiff) * translateXGeneral;
What type of mathematics is this and how can I learn more to learn to make custom animating views as so?
- Assistant
The mathematics used in this code snippet involve trigonometry, linear interpolation, and some geometry. Trigonometry is the study of relationships between angles and lengths of triangles. Linear interpolation is a method to estimate intermediate data points between known data points. Geometry is a branch of mathematics that studies the size, shape, and position of objects in space.
To learn more about these concepts and create custom animating views, you should focus on the following topics:
-
Trigonometry: Understand the basics of sine, cosine, tangent functions and their relationships. Learn about the inverse trigonometric functions, such as atan() used in the code.
-
Geometry: Learn about shapes, size, and properties of objects in space, and how to calculate distances and transformations. The code snippet deals with view dimensions and scaling.
-
Linear interpolation: Understand the concept of interpolating values between known data points to create smooth animations.
-