android 动画

1.为一个activity定义进入和退出的动画:

  首先在Manifest文件中为activity 添加style属性

 <activity 
            android:name=".activity.MainTopRightDialog" 
            android:theme="@style/MyDialogStyleTop" /> 
        <activity 

   然后在styles.xml文件中定义MyDialogStyleTop属性,以及里边引用的相关属性当然还要在anim文件夹下编写push_top_in2等动画文件:

  

 <style name="AnimTop2" parent="@android:style/Animation">  
    	<item name="android:windowEnterAnimation">@anim/push_top_in2</item>
        <item name="android:windowExitAnimation">@anim/push_top_out2</item>
	</style>
    
    <style name="MyDialogStyleTop" parent="android:Theme.Dialog" >
        <item name="android:windowAnimationStyle">@style/AnimTop2</item>
        <item name="android:windowFrame">@null</item><!--边框-->
        <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上-->
        <item name="android:windowIsTranslucent">true</item><!--半透明-->
        <item name="android:windowNoTitle">true</item><!--无标题-->
        <item name="android:windowBackground">@android:color/transparent</item><!--背景透明-->
        <item name="android:backgroundDimEnabled">false</item><!--模糊-->        
     </style>


  下面是animpush_top_in2.xml 
<?xml version="1.0" encoding="utf-8"?>
<!-- 上下滑入式 -->
<scale   xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
        android:fromXScale="1.0"   
        android:toXScale="1.0"   
        android:fromYScale="0"   
        android:toYScale="1.0"   
        android:pivotX="0"  
        android:pivotY="80%"   
        android:duration="800" /> 


2.

    对于点击之后触发事件而进行的动画可以用先编写动画文件,再加载,然后用相应的view启动

 Animation anim=AnimationUtils.loadAnimation(this,R.anim.my_rotate_action); 
 findViewById(R.id.TextView01).startAnimation(anim); 
或者像下面这样:

public void startAnim () {   //定义摇一摇动画动画
		AnimationSet animup = new AnimationSet(true);
		TranslateAnimation mytranslateanimup0 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,-0.5f);
		mytranslateanimup0.setDuration(1000);
		TranslateAnimation mytranslateanimup1 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,+0.5f);
		mytranslateanimup1.setDuration(1000);
		mytranslateanimup1.setStartOffset(1000);
		animup.addAnimation(mytranslateanimup0);
		animup.addAnimation(mytranslateanimup1);
		mImgUp.startAnimation(animup);
		
		AnimationSet animdn = new AnimationSet(true);
		TranslateAnimation mytranslateanimdn0 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,+0.5f);
		mytranslateanimdn0.setDuration(1000);
		TranslateAnimation mytranslateanimdn1 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,-0.5f);
		mytranslateanimdn1.setDuration(1000);
		mytranslateanimdn1.setStartOffset(1000);
		animdn.addAnimation(mytranslateanimdn0);
		animdn.addAnimation(mytranslateanimdn1);
		mImgDn.startAnimation(animdn);	
	}


android 动画,布布扣,bubuko.com

android 动画

上一篇:Proguard进行Android代码混淆


下一篇:Android:使用命令行工具adb、mksdcard等