我想通过屏幕上的按钮增加和减少音量。我这里的代码:减少和增加浮动增量android
//variables
float leftVolume = 0.5f;
float rightVolume = 0.5f;
public void lowerVolume(View view)
{ float decrement = 0.2f;
rightVolume -= decrement;
leftVolume -= decrement;
Log.d("Values","This is the value of volume"+ leftVolume);
}
public void raiseVolume(View view)
{ float increment = 0.2f;
rightVolume = ++increment;
leftVolume = ++increment;
Log.d("Values","This is the value of volume"+ rightVolume);
}
的日志中显示了一些疯狂的值,如母鸡我点击rasieVolume,它进入1.2F并在那里停留。
ahhh我明白现在谢谢。那么如何让它每次点击按钮时减少0.2?对不起,如果这是明显的! – hgzy
从你原来的代码看,你的'lowerVolume()'方法应该按照预期工作。 'rightVolume - = decrement'语句应该正确地减少音量。很高兴提供帮助,如果您觉得它解决了您的问题,请接受我的答案! – NoChinDeluxe