本文实例为大家分享了Android Studio实现补间动画的具体代码,供大家参考,具体内容如下
补间动画是给出初始位置和结束位置,中间由系统自动补充的动画
1、补间动画的配置文件:scale.xml
2、布局文件:animal_patching.xml
3、main.java
sacle.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <scale
- android:duration="3000"(运动时间)
- android:toYScale="0.5"(结束大小)
- android:toXScale="0.5"
- android:pivotY="50%"(运动中心位置)
- android:pivotX="50%"
- android:fromXScale="1"(初始大小)
- android:fromYScale="1"/>
- </set>
animal_patching
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:gravity="center"
- xmlns:android="http://schemas.android.com/apk/res/android">
- <ImageView
- android:id="@+id/image"
- android:background="@drawable/boy"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- </LinearLayout>
main.java
- package com.example.imageview;
-
- import androidx.appcompat.app.AppCompatActivity;
-
- import android.os.Bundle;
- import android.view.View;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.widget.ImageView;
-
- public class MainActivity<i> extends AppCompatActivity {
- /*
- private static final String TAG = "leo";
- private NotificationManager manager;
- private Notification notification;
- private PopupWindow popupWindow;
- //创建一个数组,内部元素为Bean类型;
- private List<Bean> data = new ArrayList<>();
- */
- private boolean flag = true;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.cartoon_patching);
-
- ImageView imageView = findViewById(R.id.image);
-
- imageView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- //透明度***********************************
- // Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.alpad_1);
- // imageView.startAnimation(animation);
- //旋转************************************
- // Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.rotate);
- // imageView.startAnimation(animation);
- //大小缩放**********************************
- // Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.scale);
- // imageView.startAnimation(animation);
- //平移************************************
- Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.translate);
- imageView.startAnimation(animation);
- }
- });
-
-
- }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。