Android animation TranslateAnimation application details
AlphaAnimation Transparency Animation effect
ScaleAnimation Scales the animation effect
TranslateAnimation Displacement animation effect
RotateAnimation Rotation animation effect
This section explains TranslateAnimation, which is commonly used. For example, the animation of the menu bar of QQ and NetEase news can be realized with TranslateAnimation.
Animation is defined by TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
Parameter description:
float fromXDelta The difference between the point at which the animation starts and the X coordinate of the current View
The difference between the end point of the float toXDelta animation and the current View X coordinate
The difference between the point at which the float fromYDelta animation starts and the current View Y coordinate
The difference between the point at which the float toYDelta animation starts and the current View Y coordinate
Common methods:
animation.setDuration(long durationMillis); // Set the animation duration
animation.setRepeatCount(int i); // Set the number of repetitions
animation.setRepeatMode(Animation.REVERSE); // Set the execution in the reverse direction
Xml attributes:
android:duration: indicates the duration of the animation
android:repeatCount: defines the time for the animation to repeat
Code:
public class MainActivity extends Activity {
ImageView image;
Button start;
Button cancel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.main_img);
start = (Button) findViewById(R.id.main_start);
cancel = (Button) findViewById(R.id.main_cancel);
/** Set the displacement animation to shift to the right 150 */
final TranslateAnimation animation = new TranslateAnimation(0, 150,0, 0); Final TranslateAnimation Animation = New translateAnimation (0, 150,0);
animation.setDuration(2000); // Set the animation duration
animation.setRepeatCount(2); // Set the number of repetitions
animation.setRepeatMode(Animation.REVERSE); // Set the execution in the reverse direction
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** Start animation */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** End animation */
animation.cancel();
}
});
}
}
Effect:
Related article
-
The Flutter application implements privacy screen sample parsing
This article mainly introduces the Flutter application to achieve privacy screen example analysis, friends in need can use for reference, hope to be helpful, I wish you a lot of progress, early promotion and pay rise2023-09-09 -
Android empty edit box content function implementation instance code
This article mainly introduces the realization of Android edit box data function example code, very practical value, the need of friends can refer to the next.2017-03-03 -
The ContentProvider client processes the logical analysis of the provider
This article mainly introduces the logic analysis of the ContentProvider client processing provider. Friends in need can draw on it for reference. I hope it can be helpful2022-10-10 -
Set the interface to develop Preference Library data reconstruction mechanism detailed explanation
This article mainly introduces a detailed explanation of the data reconstruction mechanism of Preference Library, which is a powerful tool for setting interface development. If you need it, you can use it for reference. I hope it can be helpful2022-10-10 -
Android BitmapUtils tool class usage details
This article mainly introduces the use of Android BitmapUtils tool class in detail for everyone, has a certain reference value, interested partners can refer to it2018-07-07 -
Android tween animation implementation example
This article mainly introduces the implementation of the Android tween animation example, the article through the example code is very detailed, for everyone's study or work has a certain reference learning value, the need of friends below with the small series to study together2023-04-04 -
Android ListView Item click effect customization
This article mainly introduces the Android ListView Item click effect of customization related information, need friends can refer to2017-07-07 -
Example of Android improved Activity+Intent usage
This article mainly introduces the Android to improve the Activity+Intent usage, is a very practical function, need friends can refer to2014-08-08 -
Android development DatePickerDialog, TimePickerDialog time and date dialog usage examples
This article mainly introduces the usage of DatePickerDialog and TimePickerDialog in the development of Android, and analyzes the display of DatePickerDialog and TimePickerDialog in the form of examples Close operation skills, need friends can refer to the next2019-03-03 -
Android UI implementation of multi-level tree list TreeView example
This article mainly introduces the implementation of Android UI multi-level list TreeView example, TreeView is a common multi-level list tree in Windows, interested can understand.2017-03-03
Latest comments