您也可以使用「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