您也可以使用“setKeepScreenOn(真)”的方法,以保持在屏幕上,比方说你有一个(根)的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);
然后你就可以在你的动画setKeepScreenOn(假)设置AnimationListener再次:
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) {
}
});
感谢它以这种方式工作,但我只有一个担忧,那就是PowerManager.SCREEN_BRIGHT_WAKE_LOCK已被弃用,有没有其他选择? – sam
我目前没有任何意识到。 – gruszczy