美文网首页
图片缓慢放大

图片缓慢放大

作者: FourJ | 来源:发表于2017-02-13 14:46 被阅读0次

    MainActivity.java

    package com.example.mysamll.app.imgscale;
    
    import android.app.Activity;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;
    import android.widget.ImageView;
    import android.widget.Toast;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Animation animation = AnimationUtils.loadAnimation(this,R.anim.enlarge);
            animation.setFillAfter(true);
            ((ImageView) findViewById(R.id.my_img)).startAnimation(animation);
            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
    
                }
    
                @Override
                public void onAnimationEnd(Animation animation) {
                    Toast.makeText(MainActivity.this,"stop!",Toast.LENGTH_SHORT).show();
                }
    
                @Override
                public void onAnimationRepeat(Animation animation) {
    
                }
            });
    
        }
    }
    
    
    

    actity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <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"
        tools:context="com.example.mysamll.app.imgscale.MainActivity">
    
        <ImageView
            android:id="@+id/my_img"
            android:src="@mipmap/bird"
            android:scaleType="fitXY"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>
    
    

    /res/anim/enlarge.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:shareInterpolator="false">
    
        <scale
            android:duration="8000"
            android:fromXScale="1.0"
            android:fromYScale="1.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toXScale="1.3"
            android:toYScale="1.3"
            />
    
    </set>
    

    相关文章

      网友评论

          本文标题:图片缓慢放大

          本文链接:https://www.haomeiwen.com/subject/ifevuttx.html