您还可以使用“setKeepScreenOn(true)”方法来保持屏幕打开,假设您有一个(根)RelativeLayout,您的动画在其中发生:
private RelativeLayout rLayout;
在 OnCreate() 中获得想要的布局:
final WatchViewStub stub = (WatchViewStub)
findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new
WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
// rLayout 是动画发生的根布局
rLayout = (RelativeLayout) stub.
findViewById(R.id.your_layout);
relativeLayout.setKeepScreenOn(true);
然后你可以在你的动画上设置一个 AnimationListener 来再次 setKeepScreenOn(false) :
yourAnimation.setAnimationListener(new
Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if(animation.hasEnded())
rLayout.setKeepScreenOn(false);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});