3

I want to move an image over the screen by the accelerometer detection, but the only example I found on is something like this:

public void onSensorChanged(SensorEvent event){
float x = event.values[0];
float y = event.values[1];
if (Math.abs(x) > Math.abs(y)) {
    if (x < 0) {
        image.setImageResource(R.drawable.right);
        textView.setText("You tilt the device right");
    }
    if (x > 0) {
        image.setImageResource(R.drawable.left);
        textView.setText("You tilt the device left");
    }
 } else {
    if (y < 0) {
        image.setImageResource(R.drawable.up);
        textView.setText("You tilt the device up");
    }
    if (y > 0) {
        image.setImageResource(R.drawable.down);
        textView.setText("You tilt the device down");
    }
 }
 if (x > (-2) && x < (2) && y > (-2) && y < (2)) {
    image.setImageResource(R.drawable.center);
    textView.setText("Not tilt device");
 }
}

That code only displays a different image depends on the tilt of the phone, but I want to move the same image like "a ball into the screen".

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Brandon Zamudio
  • 2,853
  • 4
  • 18
  • 34
  • `in this splash I want to move an image over the screen by the accelerometer detection` - How long will this splash screen last, if you have the time to play with a falling ball?! If I am to see a splash screen, it must be for a **valid** reason: **1** - Short (not longer than 5 secs) intro / app title. **2** Loading some data and/or UI elements. If I'll want to play with a falling ball, I'll install a specific app. – Phantômaxx Nov 13 '15 at 17:52
  • I love you Frank... nice to see you again. But, true... that would be a terrible UX experience. Splash screen should not last more than 1.5 or 2 sec... more than that, will be annoying for the user. – Mariano Zorrilla Nov 13 '15 at 17:54
  • @MarianoZorrilla Thanks, mate! Well, even something a bit longer (a nice picture, a small animation, a title) - or, better, as much as needed to load the data or the UI Views. I really can't imagine the user of an app willing (forced?) to play some game before using that app... – Phantômaxx Nov 13 '15 at 17:56
  • 2 MINUTES? Are you sure??? Gettings responses from webservices are over an Async Connection... while the Activity is still alive, you can do anything you want other the UI Thread. With 2 min waiting I'll uninstall the app ASAP. Also, you most ALWAYS get a tiny API response and if you have a list, use pagination. – Mariano Zorrilla Nov 13 '15 at 18:05
  • Well actually i'ts a requeriment, it's to start the app that takes a lot of time charging all data, incluides maps and connections. The first response will take 2 min for sure 'cause the requeriment is to show inmediately the current location of a GPS that update its location every 2 min. If not a requeriment I only can show the last update. – Brandon Zamudio Nov 13 '15 at 18:15
  • Anyway, in splash screen or not, I want to move an image with the sensor so I edited the question – Brandon Zamudio Nov 13 '15 at 18:20
  • If really necessary... you should add a progress bar into your splash. For the sensor thing: http://stackoverflow.com/a/6469596/3743245 (also, check for "move sprites with sensor android"... there is dozens of examples. – Mariano Zorrilla Nov 13 '15 at 18:24
  • How can I change the shape for an image in that code? – Brandon Zamudio Nov 13 '15 at 18:37
  • Well, he is using a ShapeDrawable... at the of the day, is a Drawable anyway. You can then use a bitmapDrawable and your desire image :) – Mariano Zorrilla Nov 13 '15 at 19:37

0 Answers0