zoukankan      html  css  js  c++  java
  • android设置图片变化的四种效果代码

    activity代码如下:

    package com.example.chapter12_graphic_animation;

     

    import android.os.Bundle;

    import android.app.Activity;

    import android.content.res.Resources;

    import android.graphics.drawable.Drawable;

    import android.view.Menu;

    import android.view.View;

    import android.view.View.OnClickListener;

    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;

    import android.widget.Button;

    import android.widget.ImageView;

     

    public class MainActivity extends Activity {

     

    private Button b1,b2,b3,b4;

     

    private ImageView girlImage;

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            Resources res = getResources();

            Drawable drawable = res.getDrawable(R.drawable.test);

            this.getWindow().setBackgroundDrawable(drawable);

            setContentView(R.layout.main);

            

            girlImage=(ImageView)findViewById(R.id.ImageView01);

            

            b1=(Button)findViewById(R.id.Button01);

            b2=(Button)findViewById(R.id.Button02);

            b3=(Button)findViewById(R.id.Button03);

            b4=(Button)findViewById(R.id.Button04);

            

            

            

            b1.setOnClickListener(new OnClickListener(){

     

    public void onClick(View arg0) {

    //创建Scale尺寸变化动画

    Animation scaleAnimation =new ScaleAnimation(0f,1f,0f,1f,

    Animation.RELATIVE_TO_SELF,0.5f,

    Animation.RELATIVE_TO_SELF,0.5f);

    //设置动画持续的时常

    scaleAnimation.setDuration(3000);

    //开始动画

    girlImage.startAnimation(scaleAnimation);

     

     

    }

            

            });

            

            b2.setOnClickListener(new OnClickListener(){

     

    public void onClick(View arg0) {

    //创建Scale尺寸变化动画

    Animation alphaAnimation =new AlphaAnimation(0.1f,1.0f);

    //设置动画持续的时常

    alphaAnimation.setDuration(3000);

     

    //开始动画

    girlImage.startAnimation(alphaAnimation);

     

     

    }

            

            });

            b3.setOnClickListener(new OnClickListener(){

     

    public void onClick(View arg0) {

    //创建Scale尺寸变化动画

    Animation translateAnimation =new TranslateAnimation(10,100,10,100);

    //设置动画持续的时常

    translateAnimation.setDuration(3000);

    //开始动画

    girlImage.startAnimation(translateAnimation);

     

     

    }

            

            });

            b4.setOnClickListener(new OnClickListener(){

     

    public void onClick(View arg0) {

    //创建Scale尺寸变化动画

    Animation rotateAnimation =new RotateAnimation(0f,+360f,

    Animation.RELATIVE_TO_SELF,0.5f,

    Animation.RELATIVE_TO_SELF,0.5f);

    //设置动画持续的时常

    rotateAnimation.setDuration(3000);

    //开始动画

    girlImage.startAnimation(rotateAnimation);

     

     

    }

            

            });

        }

        

        //为按钮添加监听事件

        

     

        @Override

        public boolean onCreateOptionsMenu(Menu menu) {

            getMenuInflater().inflate(R.menu.main, menu);

            return true;

        }

    }

     

    XML代码设置如下:

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:tools="http://schemas.android.com/tools"

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        >

     

        <Button

            android:id="@+id/Button01"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="Test Scale.." />

     

        <Button

            android:id="@+id/Button02"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            

            android:text="Test Alpha..." />

     

        <Button

            android:id="@+id/Button03"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

           

            android:text="Test Translate..." />

     

        <Button

            android:id="@+id/Button04"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

           

            android:text="Test Rotate..." />

     

        <ImageView

            android:id="@+id/ImageView01"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentBottom="true"

            android:src="@drawable/girl" />

     

    </LinearLayout>

     

  • 相关阅读:
    产品经理做产品设计的九步法
    产品经理要懂多少技术?
    产品经理如何注重细节意识的培养
    产品经理如何在技术人员面前更有说服力?
    从程序员到项目经理:每个人都是管理者
    我的人才管理方式
    一个关于内部类的小例子
    java中的全局变量与静态变量的区别与联系?有时候为什么专门定义静态变量。(标题党~~)
    举一反三,一小步。
    中国移动的企业文化 ,以及中国移动都有那些业务?
  • 原文地址:https://www.cnblogs.com/laifu/p/3308444.html
Copyright © 2011-2022 走看看