【发布时间】:2017-12-26 16:51:20
【问题描述】:
在 Android 活动中,我使用 CountDownTimer,如下所示:
timer = new CountDownTimer(time, 1000) {
public void onTick(long millisUntilFinished) {
timeView.setText(String.format(Locale.getDefault(), "%ds", millisUntilFinished / 1000));
if (millisUntilFinished <= 10000) {
// Blinking text
ViewUtil.setBlinking(timeView,Animation.INFINITE);
} else {
timeView.clearAnimation();
}
}
public void onFinish() {
timeView.clearAnimation();
timeView.setText("0s");
}.start();
此计时器仅以秒为单位倒计时。在同一个活动中,我还使用PopupWindow 类显示了一个弹出窗口,如下所示:
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
ConstraintLayout mRelativeLayout = (ConstraintLayout) findViewById(R.id.task_layout);
View customView = inflater.inflate(R.layout.popup_window,mRelativeLayout,false);
mPopupWindow = new PopupWindow(
customView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
mPopupWindow.setElevation(5.0f);
mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);
问题是,一旦弹出窗口出现,CountDownTimer 就会以某种方式停止。我想要的是CountDownTimer 在弹出窗口出现并且背景视图仍然更新时也会运行。
如何做到这一点?
【问题讨论】:
标签: android popupwindow countdowntimer android-popupwindow