学习不连续,很容易遗忘!一个简单的空指针提示,让我郁闷3小时,3小时啊!
不足的地方:①没有系统的去写一个demo,②API查阅也是个问题,③我还不会翻墙去看国外潮流的网站!(结合这三条,就是个HELLO)
图片的缩放,旋转,透明操作,自己去写了真的很简单!我使用的方式是XML定义,我的环境是ANDROID 4.2.2
XML中的属性定义,可以每个都试一下,我一直在做其他软件开发,对于这些属性还是不陌生。
A,缩放
定义一个XML,如下 (小放大)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="2.0"
android:toYScale="2.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"/>
</set>
定义一个XML,如下 (大缩小)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="0.5"
android:toYScale="0.5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"/>
</set>
B,旋转
定义一个XML,如下
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="90"
android:duration="3000"
/>
</set>
C,透明
定义一个XML,如下
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
android:toAlpha="0"
android:duration="3000"
/>
</set>
定义好XML之后,就是在ANDROID程序中调用这些XML,来达到我们想要的效果了,效果前的原图如下(图片为网上下载,如有不妥,请告之):
代码调用如下(自己写来学习的,当中的各种命名不规范),对于我这超级新手都能理解,我想注释应该不会有:
package com.example.tween_ys;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Matrix;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
public Animation animation;
public ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button4 = (Button) this.findViewById(R.id.t);
Button button3 = (Button) this.findViewById(R.id.xz);
Button button2 = (Button) this.findViewById(R.id.xd);
Button button1 = (Button) this.findViewById(R.id.dx);
image = (ImageView) findViewById(R.id.img);
button4.setOnClickListener(this);
button3.setOnClickListener(this);
button2.setOnClickListener(this);
button1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.t:
Toast.makeText(MainActivity.this.getApplicationContext(), "透明", 0)
.show();
animation = AnimationUtils.loadAnimation(MainActivity.this,
R.anim.anima);
image.startAnimation(animation);
break;
case R.id.dx:
Toast.makeText(MainActivity.this.getApplicationContext(), "大缩小", 0)
.show();
animation = AnimationUtils.loadAnimation(MainActivity.this,
R.anim.sf);
image.startAnimation(animation);
break;
case R.id.xd:
Toast.makeText(MainActivity.this.getApplicationContext(), "小放大", 0)
.show();
animation = AnimationUtils.loadAnimation(MainActivity.this,
R.anim.xd);
image.startAnimation(animation);
break;
case R.id.xz:
Toast.makeText(MainActivity.this.getApplicationContext(), "旋转", 0)
.show();
animation = AnimationUtils.loadAnimation(MainActivity.this,
R.anim.xz);
image.startAnimation(animation);
break;
default:
break;
}
}
}
程序运行之后的效果:
A,缩放
B,选择
C,透明