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中,然后组合动画一起起作用。

        未实现--------

  • 相关阅读:
    设置github使用的SSH key
    Github的两种协议SSH和HTTPS
    OSChina 周一乱弹 —— 为什么人类和人工智能定要一战
    OSChina 周一乱弹 —— 为什么人类和人工智能定要一战
    APP路由还能这样玩
    APP路由还能这样玩
    APP路由还能这样玩
    APP路由还能这样玩
    掘金技术社区沸点指南(试行版)
    掘金技术社区沸点指南(试行版)
  • 原文地址:https://www.cnblogs.com/childhooding/p/4348434.html
Copyright © 2011-2022 走看看