0

I'm developing an Android App with Xamarin.Android and try to update a View about 50 times per second. I used the RelativeLayout.LayoutParams to change the Margin of the View, so that it is moving around depending on the accelerometer values. Unfortunately this does not work well, because it seems like android does not redraw fast enought. Is there an alternative for LayoutParams, or how can I force Android to redraw my View faster? The View is only a small ImageView. It should not be a lot of work to draw it to it's new position. So I don't know why this is a problem for Android. Thanks in advance!

M.D.
  • 273
  • 1
  • 5
  • 18
  • 1
    `update a View about 50 times per second` seems to be too much in a second. I would highly recommend you read how to debug UI performance: https://developer.android.com/studio/profile/systrace.html – Jon Douglas Jan 19 '17 at 20:26
  • Thanks for the comment and the link. But when I go back to about 25 updates per second it is absoultely looking like slow motion. – M.D. Jan 20 '17 at 07:04
  • By the way, my Lumia 650 (slow Windows Phone) is running the exactly same code like a charm (Updating every 100 CPU ticks). So why is my new Android device not able to do so? – M.D. Jan 20 '17 at 07:06
  • Now i tried with ImageView.SetX() / SetY() Methods instead of LayoutParams.SetMargin(). But i think there is no difference :( – M.D. Jan 20 '17 at 13:08
  • I agree with Jon, update a view about 50 times per second seems to be too much, and I think the performance is also related to the device. What're you trying to do? Redrawing the view all the time or just move some controls on the view? – panda Jan 23 '17 at 07:22
  • I just move one single view. Tested on a CUBOT Dinosaur with Android 6.0 – M.D. Jan 23 '17 at 08:16

1 Answers1

0

Ok, it seems like the problem was not the android performance. Had some thread based mistakes in my code. Sorry for that. By the way I like to tell you what the solution was.

I wrote a new class extending RelativeLayout and override the onDraw() Method. This class wrapped my other stuff which is needed for calculation and movement. To move the View I also had to call postInvalidate() Method.

Thanks!

M.D.
  • 273
  • 1
  • 5
  • 18