Mic*_*kis 1 android onclick imageview android-animation
为视图创建动画..来自developer.android.com:
ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
spaceshipImage.startAnimation(hyperspaceJumpAnimation);
Run Code Online (Sandbox Code Playgroud)
我想知道我是否可以扩展ImageView所以我创建的每个MyImageView在点击时都会有动画.
我还应该在MyImageView类之外为每个MyImageView设置一个不同的OnClickListener.
那可能吗?
尝试这种方法......
public class MyImageView extends ImageView implements
View.OnClickListener {
private View.OnClickListener clickListener;
public MyImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setOnClickListener(this);
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
setOnClickListener(this);
}
public MyImageView(Context context) {
super(context);
setOnClickListener(this);
}
@Override
public void setOnClickListener(OnClickListener l) {
if (l == this) {
super.setOnClickListener(l);
} else {
clickListener = l;
}
}
@Override
public void onClick(View v) {
// start the Animation...
// handle click event yourself and pass the event to supplied
// listener also...
if (clickListener != null) {
clickListener.onClick(this);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5037 次 |
| 最近记录: |