【发布时间】:2023-03-13 01:22:01
【问题描述】:
我建了一个类(比如制作简单动画的类):
public class myAnimations {
private Animation animation;
private ImageView imageView;
public myAnimations(ImageView img) {
super();
this.imageView = img;
}
public void rotate(int duration, int repeat) {
animation = new RotateAnimation(0.0f, 360.0f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animation.setRepeatCount(repeat);
animation.setDuration(duration);
}
public void play() {
imageView.startAnimation(animation);
}
public void stop() {
animation.setRepeatCount(0);
}
}
我可以这样使用它:
ImageView myImage = (ImageView) findViewById(R.id.my_image);
myAnimations animation = new myAnimations(myImage);
animation.rotate(1000, 10);
animation.play(); //from this way…
但如果我想像这样使用它:
ImageView myImage = (ImageView) findViewById(R.id.my_image);
myAnimations animation = new myAnimations(myImage);
animation.rotate(1000, 10).play(); //…to this way
所以我可以调用这个 double 方法(我不知道名字),我应该如何构建我的类?
PS 如果你知道我需要的名字,请随时编辑标题。
【问题讨论】:
-
请注意Java中的类名以大写开头。这是一个严格遵守的约定,它有助于使您的代码保持清晰,避免歧义。