我的小学和中学的进步是同时增长的,中学的进步比小学的进步快。
每次我更新主要进度时,次要进度都会丢失(就像它为零或小于主要进度一样)。这会产生令人讨厌的闪烁。
我发现的唯一解决方法是在设置主数据库后将辅助数据库设置为自身。我添加了“+1”,因为 SeekBar 有一个检查,如果我设置相同的值,则不会重绘。
mSeekBar.setProgress(newPosition);
mSeekBar.setSecondaryProgress(mSeekBar.getSecondaryProgress()+1); // WTF?
第二行可能会修复它,但它看起来很荒谬,而且我认为效率也很低。
这发生在 Lollipop (5.0.1) - API 21 上。
它以前工作得很好 - 不明白为什么。
如果我针对 API 级别 19 进行构建,则效果很好。 (视频:API19搜索栏 http://youtu.be/7Xo1v9GHtJ4)
targetSdkVersion 19
compile 'com.android.support:appcompat-v7:19.+'
如果我针对 API 级别 21 进行构建,它就会闪烁。 (视频:API21SeekBar http://youtu.be/_tbGEgp6uJs)
targetSdkVersion 21
compile 'com.android.support:appcompat-v7:21.+'
完整的示例活动代码如下:
int delay1 = 1000;
int delay2 = 200;
int primaryProgress;
int secondaryProgress;
boolean mStarted;
Button mButton;
SeekBar mSeekBar;
Handler h1 = new Handler();
Handler h2 = new Handler();
Runnable primary = new Runnable() {
@Override
public void run() {
primaryProgress = (primaryProgress + 1) % 100;
mSeekBar.setProgress(primaryProgress);
h1.postDelayed(primary, delay1);
}
};
Runnable secondary = new Runnable() {
@Override
public void run() {
secondaryProgress = (secondaryProgress + 1) % 100;
mSeekBar.setSecondaryProgress(secondaryProgress);
h2.postDelayed(secondary, delay2);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButton = (Button)findViewById(R.id.button);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonClick();
}
});
mSeekBar = (SeekBar)findViewById(R.id.seekBar);
}
private void buttonClick() {
mStarted = !mStarted;
if (mStarted) {
mButton.setText("Started");
h1.postDelayed(primary, delay1);
h2.postDelayed(secondary, delay2);
} else {
mButton.setText("Stopped");
h1.removeCallbacks(primary);
h2.removeCallbacks(secondary);
}
}