Я пытаюсь реализовать вид спидометра.Я получаю информацию о количестве раундов в минуту, ускорении и нагрузке двигателя через Bluetooth, и я пытаюсь отобразить их на экране с 3 стрелками, которые должны указывать в правильном направлении.я пытался использовать анимацию поворота каждый раз, когда я получаю данные (10-100 мс), чтобы настроить стрелки.но это делает мой интерфейс крайне медленным.500 мс, чтобы среагировать на нажатие кнопки.Кто-нибудь знает, как заставить это работать лучше?
исходный код:
public void setTacho()
{
//rotate Tachonadel
Rpmcurrentdegree=Rpmcurrentdegree+Rpmdegree;
Rpmdegree=((rpms-lastrpm)*RPMtoDegree);
RpmAnim=new RotateAnimation((float)Rpmcurrentdegree, (float)Rpmdegree, ivNadel.getWidth()/2, ivNadel.getHeight()/2);
RpmAnim.setFillEnabled(true);
RpmAnim.setFillAfter(true);
ivNadel.setAnimation(RpmAnim);
RpmAnim.start();
//rotate Boostbalken
currentBoostDegree=currentBoostDegree+BoostDegree;
BoostDegree=(boost-lastBoost)*BOOSTtoDegree;
//rotate Loadbalken
currentLoadDegree=currentLoadDegree+LoadDegree;
LoadDegree=(load-lastLoad)*LOADtoDegree;
BoostAnim=new RotateAnimation((float)-currentBoostDegree, (float)-BoostDegree, ivBoost.getWidth()/2, ivBoost.getHeight()/2);
BoostAnim.setFillEnabled(true);
BoostAnim.setFillAfter(true);
ivBoost.setAnimation(BoostAnim);
BoostAnim.start();
LoadAnim=new RotateAnimation((float)currentLoadDegree, (float)LoadDegree, ivLoad.getWidth()/2, ivLoad.getHeight()/2);
LoadAnim.setFillEnabled(true);
LoadAnim.setFillAfter(true);
ivLoad.setAnimation(LoadAnim);
LoadAnim.start();
}
, когда я пытаюсь сделать вращение только, если значения изменились, тогда это работает, только когда они меняютсяесли это не так, стрелки возвращаются в нулевое положение.Не установлено ли после сообщения, что оно должно занимать новую позицию?
код:
public void setTacho()
{
//rotate Tachonadel
Rpmcurrentdegree=Rpmcurrentdegree+Rpmdegree;
Rpmdegree=((rpms-lastrpm)*RPMtoDegree);
if(Rpmdegree!=0)
{
RpmAnim=new RotateAnimation((float)Rpmcurrentdegree, (float)Rpmdegree, ivNadel.getWidth()/2, ivNadel.getHeight()/2);
RpmAnim.setFillEnabled(true);
RpmAnim.setFillAfter(true);
ivNadel.setAnimation(RpmAnim);
RpmAnim.start();
}
//rotate Boostbalken
currentBoostDegree=currentBoostDegree+BoostDegree;
BoostDegree=(boost-lastBoost)*BOOSTtoDegree;
//rotate Loadbalken
currentLoadDegree=currentLoadDegree+LoadDegree;
LoadDegree=(load-lastLoad)*LOADtoDegree;
if(BoostDegree!=0)
{
BoostAnim=new RotateAnimation((float)-currentBoostDegree, (float)-BoostDegree, ivBoost.getWidth()/2, ivBoost.getHeight()/2);
BoostAnim.setFillEnabled(true);
BoostAnim.setFillAfter(true);
ivBoost.setAnimation(BoostAnim);
BoostAnim.start();
}
if(LoadDegree!=0)
{
LoadAnim=new RotateAnimation((float)currentLoadDegree, (float)LoadDegree, ivLoad.getWidth()/2, ivLoad.getHeight()/2);
LoadAnim.setFillEnabled(true);
LoadAnim.setFillAfter(true);
ivLoad.setAnimation(LoadAnim);
LoadAnim.start();
}
}
я не понимаю = (
thx 4 help
РЕДАКТИРОВАТЬ:
часть потока Bluetooth, который вызывает обратный вызов
while (run) {
try {
bytes = mmInStream.read(buffer);
if (connection.btCallback != null)
{
connection.btCallback.getData(buffer,bytes);
}
} catch (IOException e) {
break;
}
метод обратного вызова потока Bluetooth:
public void getData(byte[] bytes, int len)
{
setTacho();
}