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>

     

  • 相关阅读:
    Quit Procrastinating! 20 Ways to Energize Out of Your Slump
    [转]会让你人生失败的31种原因
    Control Panel Applets
    MemTest
    The server at www.abstractspoon.com is taking too long to respond.
    拖延者 <<拖延心理学>>
    [转]How to Uninstall Windows Movie Maker
    经典街机
    Causes and Cures for Procrastination
    给页面添加关键词和简介
  • 原文地址:https://www.cnblogs.com/laifu/p/3308444.html
Copyright © 2011-2022 走看看