alphaandroid
‘壹’ Android的动画四种类型中alpha的参数含义
alpha是透明度渐变的动画效果
透明度的取值范围是0-1之间
0表示完全透明,1表示完全不透明
android:fromAlpha="1.0" //这是表示动画一开始是完全不透明
android:toAlpha="0.0" //这是表示动画结果时是完全透明
android:ration="500" //这是动画的时间
‘贰’ android标题栏透明度渐变
<alpha>标签为alpha透明度节点
android:fromAlpha="1.0" 设置动画起始透明度为1.0 表示完全不透明
android:toAlpha="0.0"设置动画结束透明度为0.0 表示完全透明
也就是说alpha的取值范围为0.0 - 1.0 之间
这个动画布局设置动画从完全不透明渐变到完全透明。
view plain
<?xml
version="1.0"
encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:repeatCount="infinite"
android:ration="2000">
</alpha>
代码实现
view plain
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public
class AlphaActivity extends Activity {
/**显示动画的ImageView**/
ImageView mImageView = null;
/**透明动画**/
Animation mAnimation = null;
@Override
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.translate);
/**拿到ImageView对象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**加载透明动画**/
mAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha);
/**播放透明动画**/
mImageView.startAnimation(mAnimation);
}
}
‘叁’ Android bitmap alpha 什么是图片的alpha值,alpha值有什么作用
这个指的就是透明度,android里面xml是八位16进制数表示,譬如#ff123a11 前两位是透明度,后六位是颜色数值,也可以直接使用后6位,这样前两位的数值就默认为ff即为白色,前两位就是alpha值
‘肆’ 如何通过android实现alpha渐变动画效果
Android动画分为四种:alpha(渐变透明度),scale(渐变尺寸伸缩),translate(画面转换位置移动),rotate(画面转移旋转);今天先写第一个动画alpha。
动画效果有两种实现:
一、在xml中定义:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 透明度控制动画效果 alpha
浮点型值:
fromAlpha 属性为动画起始时透明度
toAlpha 属性为动画结束时透明度
说明:
0.0表示完全透明
1.0表示完全不透明
以上值取0.0-1.0之间的float数据类型的数字
长整型值:
ration 属性为动画持续时间
说明:
时间以毫秒为单位
-->
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:ration="5000"
/>
</set>
二、在页面Activity中声明:
Animation animation = new AlphaAnimation(0.1f, 1.0f);
animation.setDuration(5000);
完成动画渐变透明度的参数设定后,我们就要开始在应用中使用它:
public class SplashActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
View view = View.inflate(SplashActivity.this, R.layout.welcome, null);
setContentView(view);
//动画效果参数直接定义
Animation animation = new AlphaAnimation(0.1f, 1.0f);
animation.setDuration(5000);
//动画效果从XMl文件中定义
// Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
view.setAnimation(animation);
}
}
这样我们就完成了预定的动画效果,但是我们的最终目的是动画效果完毕以后跳转到相应的页面,所以我们对动画添加了监听:
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
}
});
这样的话,我们在动画的持续时间中预加载我们的资源,当动画结束以后跳转到我们的主页面;
详细步骤和完整源码可以参考:http://www.cnblogs.com/sishuiliuyun/p/3167581.html