简体   繁体   English

Android图像缩放动画

[英]Android Image zooming animation

I'm doing an android application which has image zooming animation control with start & stop buttons.(ie)I've two buttons with an image.when i click start,the image should do zooming animation.when i click stop,it should stop animation.,and again if i click start,it should resume zooming from the stopped position.How could i do that? 我正在做一个Android应用程序,它有图像缩放动画控制,带有开始和停止按钮。(即)我有两个带图像的按钮。当我点击开始,图像应该做缩放动画。当我点击停止,它应该停止动画。再次单击开始,它应该从停止位置恢复缩放。我该怎么做? Below is my working sample code: 以下是我的工作示例代码:

ImageView imageView; ImageView imageView; ScaleAnimation zoom; ScaleAnimation缩放; Animation animset; 动画动画; float gg; 漂浮gg;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    zoom = new ScaleAnimation(0, 1, 0, 1);
    zoom.setDuration(3000);

    imageView = (ImageView) findViewById(R.id.imageView1);
    imageView.startAnimation(zoom);

    ((Button) findViewById(R.id.start)).setOnClickListener(this);
    ((Button) findViewById(R.id.stop)).setOnClickListener(this);

}

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.start:
        zoom.setDuration((long) gg);
        zoom.start();

        break;
    case R.id.stop:
        gg = zoom.getDuration();
        break;

    }

}

} Thanks. } 谢谢。

try this 尝试这个

ZOOM IN ACTIVITY 放大活动

public class ZoomInActivity extends Activity implements AnimationListener {

    ImageView imgPoster;
    Button btnStart;

    // Animation
    Animation animZoomIn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zoom_in);

        imgPoster = (ImageView) findViewById(R.id.imgLogo);
        btnStart = (Button) findViewById(R.id.btnStart);

        // load the animation
        animZoomIn = AnimationUtils.loadAnimation(getApplicationContext(),
                R.anim.zoom_in);

        // set animation listener
        animZoomIn.setAnimationListener(this);

        // button click event
        btnStart.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // start the animation
                imgPoster.startAnimation(animZoomIn);
            }
        });

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        // Take any action after completing the animation

        // check for zoom in animation
        if (animation == animZoomIn) {          
        }

    }

    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

}


activity_zoom_in_XML:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:gravity="center">

    <ImageView android:id="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/man_of_steel"
        android:layout_centerInParent="true"/>

    <Button android:id="@+id/btnStart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start Animation"
        android:layout_marginTop="30dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="20dp"/>

</RelativeLayout>

make anim folder in res and create zoom_in.xml 在res中创建anim文件夹并创建zoom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="3"
        android:toYScale="3" >
    </scale>

</set>

Easy and Simple 简单易行

  • Create folder res/anim 创建文件夹res / anim
  • Put animation descriptions into res/anim folder 将动画描述放入res / anim文件夹
  • Set animation to image using below code 使用下面的代码将动画设置为图像

     ImageView image=(ImageView)findViewById(R.id.imageId); image.setAnimation(AnimationUtils.loadAnimation(this,R.anim.zoom_in_anim)); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM