zoukankan      html  css  js  c++  java
  • 补间动画

    1. layout中的 activity_main.xml 布局

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" 
        >
        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="alph"
            android:text="透明度" />
    
        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="trans"
            android:text="位移" />
    
        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="scale"
            android:text="缩放" />
    
        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="rotate"
            android:text="旋转" />
    </LinearLayout>
        
            <ImageView 
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:id="@+id/imageview"
                 android:background="@drawable/ic_launcher"
                 android:layout_centerInParent="true"
                />
        
    
    </RelativeLayout>
    

     2.透明度、旋转、缩放、位移动画代码的实现 MainActiviy.java

    public class MainActivity extends Activity {
        ImageView imageview;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    		imageview = (ImageView) findViewById(R.id.imageview);
    		
    	}
    	
        public void alph(View view){
    	  AlphaAnimation aa=new AlphaAnimation(0.0f, 1.0f);
    	  aa.setDuration(2000);
    	  aa.setRepeatCount(1);
    	  aa.setRepeatMode(Animation.REVERSE);
    	  imageview.startAnimation(aa);
    	   
         }
        public void scale(View view){
        	ScaleAnimation sa = new ScaleAnimation(0.1f, 2.0f, 0.1f, 2.0f, Animation.RELATIVE_TO_SELF, 
    				0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    		sa.setDuration(2000);
    		sa.setRepeatCount(1);
    		sa.setRepeatMode(Animation.REVERSE);
    		imageview.startAnimation(sa);
     	   
        }
        public void trans(View view){
      	  TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
      			  Animation.RELATIVE_TO_PARENT,0.5f,
      			  Animation.RELATIVE_TO_PARENT,0.0f,
      			  Animation.RELATIVE_TO_PARENT,0.0f
      			  );
      	  ta.setDuration(2000);
      	  ta.setRepeatCount(1);
      	  ta.setRepeatMode(Animation.REVERSE);
      	  imageview.startAnimation(ta);
     	   
        }
        public void rotate(View view){
        	RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF,
    				0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    		ra.setDuration(2000);
    		ra.setRepeatCount(1);
    		ra.setRepeatMode(Animation.REVERSE);
    		imageview.startAnimation(ra);
     	   
        }
        
    
    }
    

      3.组合动画,AnimationSet,把缩放、旋转、平移、透明度动画可以一起放入AnimationSet中,然后组合动画一起起作用。

        未实现--------

  • 相关阅读:
    layout_alignStar 与 android:layout_alignEnd
    Java学习过程中的一些知识点
    L1-054 福到了->团体程序设计天梯赛-练习集
    JS冒号的作用
    JS中(function(){xxx})(); 这种写法是什么意思?
    去除vue上方的60px空白
    vue-cli · Failed to download repo vuejs-templates/webpaack: Response code 404
    Windows 7 MBR的修复与Linux产品正确卸载
    折腾一天安装Centos7,以及后面恢复Win7引导的曲折历程
    Windows 7硬盘安装CentOS 6.4 双系统 (WIN7下硬盘安装Linux(Fedora 16,CentOS 6.2,Ubuntu 12.04))
  • 原文地址:https://www.cnblogs.com/childhooding/p/4348434.html
Copyright © 2011-2022 走看看