나는 내 자바 파일의 뒷부분에 정의 된 메소드를 호출하려고 해요 : 내가 디버그 모드에서 내 응용 프로그램을 실행할 때 나는 것을 볼, 그러나 ...Android Studio의 onCreate 메소드에서 Java 파일의 다른 메소드를 호출 할 수 있습니까?
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);
}
을 moveHorizontal
및 moveVertical
모두 0
으로 설정됩니다. 나는 width(1f/12f)
를 찾기 위해 코드의 나머지 부분에서 사용 해봤하고 90
를 반환 같은 방법이 잘 작동 알고있다. 이 내가 onCreate
방법 내부 width
메서드를 호출 할 수 없음을 의미 하는가? 이 문제를 해결할 방법이 있습니까?
디버깅을 시도 했습니까? 'relative1.getWidth()'가 예기치 않은 값을 반환 할 가능성이 더 높습니다 (아마도 아직 그려지지 않았을 것입니다). – John3136