新~伸缩ImageView

package com.example.scaleview;

import android.content.Context;
import android.provider.ContactsContract.CommonDataKinds.Event;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class ScaleView extends ImageView{

	Context context;
	public ScaleView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		this.context=context;
		// TODO Auto-generated constructor stub
	}

	public ScaleView(Context context, AttributeSet attrs) {
		this(context, attrs,0);
		// TODO Auto-generated constructor stub
	}

	public ScaleView(Context context) {
		this(context, null);
		// TODO Auto-generated constructor stub
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		Animation big,small;
		big=AnimationUtils.loadAnimation(context, R.anim.big);
		small=AnimationUtils.loadAnimation(context, R.anim.small);
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			this.clearAnimation();
			this.startAnimation(small);
			this.clearAnimation();
			this.startAnimation(big);
			break;

		default:
			break;
		}
		return super.onTouchEvent(event);
	}
	
}


R.anim.big和R.anim.small

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <scale 
        android:fromXScale="0.3"
        android:toXScale="1"
        android:fromYScale="0.3"
        android:toYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="200"
        />
</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <scale 
        android:fromXScale="1"
        android:toXScale="0.3"
        android:fromYScale="1"
        android:toYScale="0.3"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="200"
        />
</set>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值