今天测试Animation动画代码时, 定义了四个ImageView组件, 并分别对其设置了四个不同的动画效果, 但在设置AlphaAnimation动画的一些属性时,发生了很诡异的问题, 就是我如果设置AlphaAnimation下列属性:alphaAnimation.setFillAfter(true);
alphaAnimation.setFillBefore(false);则AlphaAnimation动画效果不受影响,符合属性设置, 但只要呈现了该组件的动画效果后, 对于其他三个组件的动画效果就会产生影响, 其他三个动画效果很诡异但在为其他三个分别设置上述属性, 并注释掉AlphaAnimation的上述属性设置代码后, 则不会对其他组件动画产生影响, 所以说这个问题很诡异,不知道大家有没有遇到过, 希望知道原因的能解答一下,谢谢!下面是全部代码:csdn貌似不能上传附件, 麻烦大家自己建工程拷贝代码进行测试
main.xml:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity = "center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id = "@+id/imageView01"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
<ImageView
android:id = "@+id/imageView02"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
<ImageView
android:id = "@+id/imageView03"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
<ImageView
android:id = "@+id/imageView04"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
</LinearLayout>
TestAnimation.javapackage snowfox.animation;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;public class TestAnimation extends Activity implements OnClickListener{
AnimationTools animationTools;
ImageView imageView01, imageView02, imageView03, imageView04;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView01 = (ImageView)findViewById(R.id.imageView01);
imageView02 = (ImageView)findViewById(R.id.imageView02);
imageView03 = (ImageView)findViewById(R.id.imageView03);
imageView04 = (ImageView)findViewById(R.id.imageView04);
animationTools = new AnimationTools();
imageView01.setOnClickListener(this);
imageView02.setOnClickListener(this);
imageView03.setOnClickListener(this);
imageView04.setOnClickListener(this);
}
@Override
public void onClick(View view)
{
switch(view.getId())
{
case R.id.imageView01:
animationTools.translateAnimation(view);
break;
case R.id.imageView02:
animationTools.rotateAnimation(view);
break;
case R.id.imageView03:
animationTools.scaleAnimation(view);
break;
case R.id.imageView04:
animationTools.alphaAnimation(view);
break;
}
}
}
AnimationToolspackage snowfox.animation;import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;public class AnimationTools
{
public void alphaAnimation(View view)
{
System.out.println("alphaAnimation");
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation .setDuration(1000);
alphaAnimation.setFillAfter(true);
alphaAnimation.setFillBefore(false);
view.startAnimation(alphaAnimation);
}
public void translateAnimation(View view)
{
System.out.println("translateAnimation");
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1.0f);
translateAnimation.setDuration(1000);
// translateAnimation.setFillAfter(true);
// translateAnimation.setFillBefore(true);
view.startAnimation(translateAnimation);
}
public void scaleAnimation(View view)
{
System.out.println("scaleAnimation");
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.1f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(1000);
// scaleAnimation.setFillAfter(true);
// scaleAnimation.setFillBefore(false);
view.startAnimation(scaleAnimation);
}
public void rotateAnimation(View view)
{
System.out.println("rotateAnimation");
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
rotateAnimation.setDuration(1000);
// rotateAnimation.setFillAfter(true);
// rotateAnimation.setFillBefore(false);
view.startAnimation(rotateAnimation);
}
}
alphaAnimation.setFillBefore(false);则AlphaAnimation动画效果不受影响,符合属性设置, 但只要呈现了该组件的动画效果后, 对于其他三个组件的动画效果就会产生影响, 其他三个动画效果很诡异但在为其他三个分别设置上述属性, 并注释掉AlphaAnimation的上述属性设置代码后, 则不会对其他组件动画产生影响, 所以说这个问题很诡异,不知道大家有没有遇到过, 希望知道原因的能解答一下,谢谢!下面是全部代码:csdn貌似不能上传附件, 麻烦大家自己建工程拷贝代码进行测试
main.xml:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity = "center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id = "@+id/imageView01"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
<ImageView
android:id = "@+id/imageView02"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
<ImageView
android:id = "@+id/imageView03"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
<ImageView
android:id = "@+id/imageView04"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
</LinearLayout>
TestAnimation.javapackage snowfox.animation;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;public class TestAnimation extends Activity implements OnClickListener{
AnimationTools animationTools;
ImageView imageView01, imageView02, imageView03, imageView04;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView01 = (ImageView)findViewById(R.id.imageView01);
imageView02 = (ImageView)findViewById(R.id.imageView02);
imageView03 = (ImageView)findViewById(R.id.imageView03);
imageView04 = (ImageView)findViewById(R.id.imageView04);
animationTools = new AnimationTools();
imageView01.setOnClickListener(this);
imageView02.setOnClickListener(this);
imageView03.setOnClickListener(this);
imageView04.setOnClickListener(this);
}
@Override
public void onClick(View view)
{
switch(view.getId())
{
case R.id.imageView01:
animationTools.translateAnimation(view);
break;
case R.id.imageView02:
animationTools.rotateAnimation(view);
break;
case R.id.imageView03:
animationTools.scaleAnimation(view);
break;
case R.id.imageView04:
animationTools.alphaAnimation(view);
break;
}
}
}
AnimationToolspackage snowfox.animation;import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;public class AnimationTools
{
public void alphaAnimation(View view)
{
System.out.println("alphaAnimation");
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation .setDuration(1000);
alphaAnimation.setFillAfter(true);
alphaAnimation.setFillBefore(false);
view.startAnimation(alphaAnimation);
}
public void translateAnimation(View view)
{
System.out.println("translateAnimation");
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1.0f);
translateAnimation.setDuration(1000);
// translateAnimation.setFillAfter(true);
// translateAnimation.setFillBefore(true);
view.startAnimation(translateAnimation);
}
public void scaleAnimation(View view)
{
System.out.println("scaleAnimation");
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.1f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(1000);
// scaleAnimation.setFillAfter(true);
// scaleAnimation.setFillBefore(false);
view.startAnimation(scaleAnimation);
}
public void rotateAnimation(View view)
{
System.out.println("rotateAnimation");
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
rotateAnimation.setDuration(1000);
// rotateAnimation.setFillAfter(true);
// rotateAnimation.setFillBefore(false);
view.startAnimation(rotateAnimation);
}
}
解决方案 »
- 求助在下一个定时启动的时候先关掉显示的activity,然后再启动他
- 多任务多线程断点下载,有暂停下载,继续下载,删除下载文件功能
- 本人菜鸟,求大神指教。一个关于android地图的问题。
- handler如何控制更新某个控制
- 没有搞android底层的吗,留个方式交流下。。。
- 【离线版】关于asp.net 与Android离线数据同步的设计思想
- 请问一下这个动画怎么实现
- android bitmap的点击事件 求助
- 软件黑屏问题
- android studio安装问题。
- emulator: ERROR: no search paths found in this AVD's configuration.
- 大家都来总结哈android出现的异常~
main.xml做如下修改就ok了:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity = "center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:gravity = "center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id = "@+id/imageView01"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
<ImageView
android:id = "@+id/imageView02"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
<ImageView
android:id = "@+id/imageView03"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
</LinearLayout>
<ImageView
android:id = "@+id/imageView04"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/icon"/>
</LinearLayout>
alpha &= 0xFF; // keep it legal
if (mAlpha != alpha) {
mAlpha = alpha;
applyColorMod();
invalidate();
}
} private void applyColorMod() {
if (mDrawable != null) {
mDrawable.setColorFilter(mColorFilter);
mDrawable.setAlpha(mAlpha * mViewAlphaScale >> 8);
}
}