2009-12-08 4 views

답변

1

루트 레이아웃을 사용했는데 처음으로 실행될 때 onCreate/onStart/onResume 메서드에서이 정보 (폭과 높이)를 얻을 수 없다는 것이 문제입니다.

그 이후 어느 순간, 크기는 (있는 LinearLayout/FrameLayout이/TableLayout을/등), 내 경우에는 내가 사용 된 루트 레이아웃에서 검색 할 수 있습니다 FrameLayout이 :

FrameLayout f = (FrameLayout) findViewById(R.id.layout_root); 
Log.d(TAG, "width " + f.getMeasuredWidth()); 
Log.d(TAG, "height " + f.getMeasuredHeight()); 

나 :

FrameLayout f = (FrameLayout) findViewById(R.id.layout_root); 
Log.d(TAG, "width " + f.getRight()); 
Log.d(TAG, "height " + f.getBottom()); 

이제 시스템 바의 높이를 알고있는 활동 높이가 활동 높이에서 전체 화면 높이를 뺀 것입니다.

어떻게 화면의 높이가 여기에 설명 얻을 : Get screen dimensions in pixels

여기에서 편집 -------------------------- ------------------------------

onCreted 메서드에서이 정보를 얻을 수있는 방법을 찾았습니다. 당신은 하나 이상의 활동을합니다. 제 경우에는 두 번째 활동을 불러오는 주요 활동이 있습니다.

main_activity에서 second_activity를 호출하기 전에 새로운 Itent에서 second_activity에 대한 추가 정보를 추가 할 수 있습니다.

int width = getIntent().getExtras().getInt("width"); 
int height = getIntent().getExtras().getInt("height"); 
: 당신이 그 일을 두 번째 활동에서 onCreate 방법에이 정보를 검색 할 수 있습니다 두 번째 활동 그 후

Intent i = new Intent(this, SecondActivity.class); 
i.putExtra("width", f.getMeasuredWidth()); 
i.putExtra("height", f.getMeasuredHeight()); 
startActivity(i); 

: 여기에 첫 번째 활동에 필요한 코드는

관련 문제