2013-03-16 90 views
0

我想在我的应用中动态启用动画,就像我们通过手动从设置>显示>动画>所有动画一样。如何在android中启用动画

我曾尝试附加代码,但无济于事,

Settings.System.putInt(getContentResolver(), Settings.System.WINDOW_ANIMATION_SCALE, 1); 
Settings.System.putInt(getContentResolver(), Settings.System.TRANSITION_ANIMATION_SCALE, 1); 

请帮

伊姆兰

+0

使XML文件/写动画代码,并添加overridePendingTransition(R.anim.slide_in_left,R.anim .slide_out_right);你试过这个吗? – Anu 2013-03-16 03:53:05

回答

0

我想,你可以为你的应用程序做到这一点,但如果你正在服用它为您的设备意味着您可以阅读标志。如果它被禁用,您可以打开设置面板以便用户启用它。

源: animation enable

0

//声明动画

动画animationSlideInLeft,animationSlideOutRight;

//现在我们giveing图像视图动画

image1 = (ImageView)findViewById(R.id.image1); 
    image2 = (ImageView)findViewById(R.id.image2); 
    image3 = (ImageView)findViewById(R.id.image3); 

    animationSlideInLeft = AnimationUtils.loadAnimation(this, 
    android.R.anim.slide_in_left); 
    animationSlideOutRight = AnimationUtils.loadAnimation(this, 
    android.R.anim.slide_out_right); 
    animationSlideInLeft.setDuration(1000); 
    animationSlideOutRight.setDuration(1000); 
    animationSlideInLeft.setAnimationListener(animationSlideInLeftListener); 
    animationSlideOutRight.setAnimationListener(animationSlideOutRightListener); 

    curSlidingImage = image1; 
    image1.startAnimation(animationSlideInLeft); 
    image1.setVisibility(View.VISIBLE); 

//创建动画听众

AnimationListener animationSlideInLeftListener 
= new AnimationListener(){ 

    @Override 
    public void onAnimationEnd(Animation animation) { 
    // TODO Auto-generated method stub 

    if(curSlidingImage == image1){ 
    image1.startAnimation(animationSlideOutRight); 
    }else if(curSlidingImage == image2){ 
    image2.startAnimation(animationSlideOutRight); 
    }else if(curSlidingImage == image3){ 
    image3.startAnimation(animationSlideOutRight); 
    } 
    } 

    @Override 
    public void onAnimationRepeat(Animation animation) { 
    // TODO Auto-generated method stub 

    } 

    @Override 
    public void onAnimationStart(Animation animation) { 
    // TODO Auto-generated method stub 

    }}; 

//和PAUS清除监听

@Override 
protected void onPause() { 
    // TODO Auto-generated method stub 
    super.onPause(); 
    image1.clearAnimation(); 
    image2.clearAnimation(); 
    image3.clearAnimation(); 
} 

Reference from here

2.Same这一个你可以用增加了XML做成RES /动画/文件夹在res /阿尼姆