80,351
社区成员
发帖
与我相关
我的任务
分享
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
layoutImg=(FrameLayout)findViewById(R.id.layoutimg);
animtest=AnimationUtils.loadAnimation(this, R.anim.animtest);
playMusic=(ImageButton)findViewById(R.id.playmusic);
playMusic.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
boolean flag=animtest.hasStarted(); //hasStarted()自从layoutImg.startAnimation后就一直返回true
Log.d(TAG, "play button clicked:"+flag);
if(!flag&&layoutImg!=null){
updateBtnView(true);
layoutImg.startAnimation(animtest);
Log.d(TAG, "play");
}else{
updateBtnView(false);
/*Question:
* 1、clearAnimation可以停止动画,但不是暂停,也就是说动画会回到起点,而不是停在当前旋转的角度。
* 2、clearAnimation后,animtest.hasStarted()仍然返回的true,请问怎样才能让它返回false?
*/
layoutImg.clearAnimation();
/*
* 以下两者皆无效
*/
// animtest.reset();
// animtest.cancel();
Log.d(TAG, "pause");
}
}
});
}
<rotate
android:fromDegrees="0"
android:toDegrees="355"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:repeatCount="-1"
android:interpolator="@android:anim/linear_interpolator"
android:duration="4000"/>
android:fromDegrees="0"
android:toDegrees="355"
android:toDegrees请改成360ObjectAnimator rot = ObjectAnimator.ofFloat(toggleButton, "rotation", 0, 359);
rot.setInterpolator(new LinearInterpolator());
rot.setDuration(4000);
rot.setRepeatCount(-1);
rot.start()
;