android:fromYDelta=“0”
android:toXDelta=“300”
android:toYDelta=“300”>
anim_rotate.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration=“3000”
android:fillAfter=“true”>
<rotate
android:fromDegrees=“0”
android:toDegrees=“200”
android:pivotX=“50%”
android:pivotY=“50%”>
anim_scale.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration=“3000”
android:fillAfter=“true”>
<scale
android:fromXScale=“1”
android:fromYScale=“1”
android:toXScale=“3”
android:toYScale=“3”
android:pivotY=“50%”
android:pivotX=“50%”>
anim_group.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration=“3000”
android:fillAfter=“true”
<alpha
android:fromAlpha=“1”
android:toAlpha=“0.5”>
<scale
android:fromXScale=“1”
android:fromYScale=“1”
android:toXScale=“3”
android:toYScale=“3”
android:pivotY=“50%”
android:pivotX=“50%”>
FourActivity.java
public class FourActivity extends AppCompatActivity implements View.OnClickListener {
private Button btn_alpha;
private Button btn_translate;
private Button btn_rotate;
private Button btn_scale;
private ImageView iv_show;
Animation animation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_four);
initView();
}
private void initView() {
btn_alpha = (Button) findViewById(R.id.btn_alpha);
btn_translate = (Button) findViewById(R.id.btn_translate);
btn_rotate = (Button) findViewById(R.id.btn_rotate);
btn_scale = (Button) findViewById(R.id.btn_scale);
iv_show = (ImageView) findViewById(R.id.iv_show);
btn_alpha.setOnClickListener(this);
btn_translate.setOnClickListener(this);
btn_rotate.setOnClickListener(this);
btn_scale.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_alpha://透明动画
//如果要用静态的动画(xml),就得用这个API
animation = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
break;
case R.id.btn_translate://位移动画
animation = AnimationUtils.loadAnimation(this, R.anim.anim_translate);
break;
case R.id.btn_rotate://旋转动画
animation = AnimationUtils.loadAnimation(this, R.anim.anim_rotate);
break;
case R.id.btn_scale://缩放动画
animation = AnimationUtils.loadAnimation(this, R.anim.anim_scale);
break;
}
iv_show.startAnimation(animation);
}
public void groupshow(View view) {//组合
animation = AnimationUtils.loadAnimation(this, R.anim.anim_group);
iv_show.startAnimation(animation);
}
}
activity_four.xml
<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=“.FourActivity”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:orientation=“horizontal”>
<Button
android:id=“@+id/btn_alpha”
android:layout_width=“0dp”
android:layout_height=“40dp”
android:layout_weight=“1”
android:text=“透明动画” />
<Button
android:id=“@+id/btn_translate”
android:layout_width=“0dp”
android:layout_height=“40dp”
android:layout_weight=“1”
android:text=“位移动画” />
<Button
android:id=“@+id/btn_rotate”
android:layout_width=“0dp”
android:layout_height=“40dp”
android:layout_weight=“1”
android:text=“旋转动画” />
<Button
android:id=“@+id/btn_scale”
android:layout_width=“0dp”
android:la
yout_height=“40dp”
android:layout_weight=“1”
android:text=“缩放动画” />
<ImageView
android:id=“@+id/iv_show”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_centerInParent=“true”
android:src=“@mipmap/ic_launcher” />
<Button
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_alignParentBottom=“true”
android:onClick=“groupshow”
android:text=“组合显示” />
最后
小编这些年深知大多数初中级Android工程师,想要提升自己,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人
都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
资料⬅专栏获取
id:onClick=“groupshow”
android:text=“组合显示” />
最后
小编这些年深知大多数初中级Android工程师,想要提升自己,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
[外链图片转存中…(img-EPkez6Wm-1719082716910)]一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人
都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
资料⬅专栏获取