Android中实现亮度渐变的干净方法?
目前,我有淡入亮度调整的代码,如下所示:Android中实现亮度渐变的干净方法?,android,brightness,fading,Android,Brightness,Fading,目前,我有淡入亮度调整的代码,如下所示: new Thread() { public void run() { for (int i = initial; i < target; i++) { final int bright = i; handle.post(new Runnable() { public void run() { float c
new Thread() {
public void run() {
for (int i = initial; i < target; i++) {
final int bright = i;
handle.post(new Runnable() {
public void run() {
float currentBright = bright / 100f;
window.getAttributes().screenBrightness = currentBright;
window.setAttributes(window.getAttributes());
});
}
try {
sleep(step);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
谢谢 在每次迭代中将亮度降低一半怎么样
然后循环将在O(对数n)中完成,而不是在当前解决方案中的O(n)。从Honeycomb,您可以使用此方法完成操作。这个。你想让设备进入睡眠状态吗?不,我只是想逐渐改变背光亮度。据我所知,没有具体的方法可以满足你的需要:-/对不起。嗯,我会试试ObjectAnimator。谢谢你的链接。你的实现方式有什么问题吗?看起来不错…我喜欢你的想法!问题是亮度衰减在一开始会非常剧烈,所以看起来有点滞后。我试过了,如果步长足够小,效果会很好。干杯@小故障我很高兴它对你有用&我是我在这里的第一个赏金我尝试过这个,但我不能实际测试它,因为我没有蜂窝设备。也许如果我们能够访问源代码,我可以在其他Android平台上实现它。
new Timer().schedule(new TimerTask() {
@Override
public void run() {
final float currentBright = counter[0] / 100f;
handle.post(new Runnable() {
public void run() {
window.getAttributes().screenBrightness = currentBright;
window.setAttributes(window.getAttributes());
if (++counter[0] <= target) {
cancel();
}
}
});
}
}, 0, step);
handle.post(new Runnable() {
public void run() {
if (counter[0] < target) {
final float currentBright = counter[0] / 100f;
window.getAttributes().screenBrightness = currentBright;
window.setAttributes(window.getAttributes());
counter[0]++;
handle.postDelayed(this, step);
}
}
});