화면 회전시 새로 띄우기

Lee HyeongJong·2022년 12월 14일
0

안드로이드

목록 보기
28/43

화면 회전시 화면을 새로 띄우자

1) 화면 회전시 Layout이 화면에 맞지 않게 바뀌는 경우를 방지하기 위해 회전시 새로 띄우도록 하자

public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        (이곳에 작업 내용을 적습니다, 생략 가능)
}

2) 가로 세로 변경시 코드

if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
	// 기기가 가로로 회전할때 할 작업
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
	// 기기가 세로로 회전할때 할 작업
}

3) 예시

//    가로 / 세로모드
    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        if (CalendarPickerPopupDialog != null) {
            CalendarPickerPopupDialog.dismiss();
            if(changeDate == false){ changeDate = true; }
            changeFinalDate = false;
            //세로
            if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
                getCalendarPickerPopupDialog();

                //가로
            } else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                getCalendarPickerPopupDialog();

            }
            changeFinalDate = true;
        }
    }

참고
https://itmir.tistory.com/288

profile
코딩을 시작해보자

0개의 댓글