Hi all i want to move an image using accelerometer values,but m not able to do it. Can anyone please help me to do this, I have already gone through sample code in android developers site but couldn’t understand properly.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To move an image, see how it’s done in this example. Basically, the key is to get a matrix of some kind, and manipulate it based off of some input, in the case of this example, the touch/drag of a user. The below code doesn’t function perfectly, but it shows the key commands and classes required to perform dragging. For more details, see the linked article.
The next part is to somehow use the accelerometer to get input. I’m going to leave it to you how to best put the two together. My source of this information is this article. There are a few basic steps.
The first step is to register the listener, and is done by this code.
The next step is to register a sensor listener. The last bit is to show what the sensor listener looks like. Note that there are 3 outputs of the accelerometer, one for each x, y, and z coordinates.
Your next step will be to figure out what the x, y, and z values are for your desired application. I suggest you take and log each of these out using a
Log.v(TAG,...)statement. Play around with tilting it, and figure out exactly what you want to do. Tune it until it has the right level of sensitivity, by seeing how far off it is from straight up and down, and having some kind of a rate of changing the x and y coordinates of the image. Good luck!