-1

I want to execute one of the following java instructions on android several times so i want to know which approach is better for performance Switch between

View.setBackgroundColor(Color.Black);

And

View.setBackgroundColor(Color.White);

Or between

View.setVisibility(View.Invisible);

And

View.setVisivility(View.Visible);

I only care about performance for this task

Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51
user8062843
  • 123
  • 1
  • 8
  • https://stackoverflow.com/questions/180158/how-do-i-time-a-methods-execution-in-java – Shawn Mehan Jun 14 '17 at 22:38
  • Thanks for that link – user8062843 Jun 14 '17 at 22:40
  • Have you tried benchmarking the alternatives​? – Lew Bloch Jun 14 '17 at 23:10
  • Remember if you do such a benchmark that android is relayouting and redrawing not immediately. So benchmarking the execution time of `View.setVisivility(View.Visible)` doesn't give you any concrete result. you have to benchmark the time it takes before you apply the change until the next frame has drawn where your changes has been applied. I don't think the performance difference is relevant at all. Better spend your dev time with something else. Also the color "solution" doesn't seem to be user friendly (i.e. you might also have to remove click listeners etc.) – sockeqwe Jun 14 '17 at 23:53
  • How can i know when the frame is rendered? – user8062843 Jun 14 '17 at 23:59

1 Answers1

0

There was a very similar question before... I think you should be asking about View.GONE, though. Or entirely removing the view from the content altogether

Obviously setting a color or visibility doesn't affect anything other than what you see. There is no performance gain from either option.

The real performance you get is to not cause a layout to be entirely redrawn

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245