-3

I don't know how to read this code. what is the equivalent code with if/else statements?

            leftPanel.getLayoutParams().width = interpolatedTime == 1
                    ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int)(targetWidth * interpolatedTime);
user3453281
  • 559
  • 5
  • 12

1 Answers1

3

It is called the ternary operator and is exactly equivalent to:

if(interpolatedTime == 1) {
    leftPanel.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
} else {
   leftPanel.getLayoutParams().width = (int)(targetWidth * interpolatedTime);
}

See http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html for the Oracle documentation for it.

aryn.galadar
  • 716
  • 4
  • 13
M A
  • 71,713
  • 13
  • 134
  • 174