view - How to rotate the image using sensor manager azimuth value in android? -



view - How to rotate the image using sensor manager azimuth value in android? -

public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //accel sensormanager = (sensormanager) getsystemservice(sensor_service); sensor = sensormanager.getdefaultsensor(sensor.type_orientation); setcontentview(r.layout.sample); } ///////////////// basics /** * called when application in background */ public void onpause() { super.onpause(); sensormanager.unregisterlistener(this); //this of import because android applications //do not close, in background //so resources hogged otherwise } /** * called when application started * or in foreground 1 time again */ public void onresume() { super.onresume(); sensormanager.registerlistener(this, sensor, rate); } //==================accel===================== /** * called when values of acceleration sensor changes * * @param e details alter */ public void onsensorchanged(sensorevent e) { float azimuth=e.values[0]; log.i("azimuth",string.valueof(azimuth)); } /** * called when accuracy of sensor changed * * @param sen sensor's accuracy changed * @param acc new accuracy grade */ public void onaccuracychanged(sensor sen, int acc) { }

here getting azimuth value using sensor manager.i want know how rotate imageview compass using azimuth value?can give thought ?how utilize ondraw function here? without draw circle or line within ondraw method?

here's how can rotate imageview:

matrix matrix=new matrix(); imageview.setscaletype(scaletype.matrix); //required matrix.postrotate((float) -azimuth, imageview.getdrawable().getbounds().width()/2, imageview.getdrawable().getbounds().height()/2); imageview.setimagematrix(matrix);

for api 11+, there's easy way:

arrow.setrotation((float) -azimuth);

you can check out blog circle , line compass.

hope helps.

android view azimuth sensormanager

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -