I'm trying to call a method that is defined later in my java file:
public int moveHorizontal;
public int moveVertical;
public RelativeLayout relative1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
relative1 = (RelativeLayout) findViewById(R.id.relative1);
moveHorizontal = width(1f/12f);
moveVertical = height(1f/12f);
}
...
public int width(float fraction) {
float relativeWidth = relative1.getWidth();
return Math.round(fraction*relativeWidth);
}
However, when I run my app in debug mode I see that moveHorizontal
and moveVertical
are both set to 0
. I know the method works fine as I've tried using it in the rest of the code to find width(1f/12f)
and it returns 90
. Does this mean that I can't call the width
method inside the onCreate
method? And is there a way around this?