상세 컨텐츠

본문 제목

안드로이드 화면 조절관련 (화면고정 등등)

스마트기기개발관련/안드로이드 개발

by AlrepondTech 2020. 9. 22. 00:12

본문

반응형

 

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 


안드로이드폰의 자판을 열면 자동으로 화면이 가로로 되어 버린다.

이렇게 바뀌지 않고 고정된 화면을 사용하고 싶다면

프로젝트를 열어 AndroidManifest.xml 을 더블클릭한다.

그리고 어플리케이션 탭을 누른다. 고정할 Activity를 선택한다.

오른쪽에 Attribute를 죽내려다 보면 ScreenOrientaion이 있다.

여기서 portrait를 선택하면 세로로 화면이 고정된다.

원하는 옵션을 선택한다!

 

 

 

출처:[코딩]안드로이드 화면 고정하기


추가팁: 매니페스트에서 각각 자신이 만든 모든 액티브에 설정해준다.  그러므로 자신이 만든 액티브를 누른다음
           위에 방법대로 하면된다.

 

 

=================================

=================================

=================================

 

 

 

출처: http://f7key.tistory.com/9

안드로이드 화면(세로, 가로) 고정 방법 - 변두리 프로그래머안드로이드 화면(세로, 가로) 고정 방법 - 변두리 프로그래머

 

 

안드로이드 엑티비티 화면을 세로 또는 가로로 고정 하시려면 
AndroidManifest.xml 과 해당엑티비티.java 파일에 다음 명령어들만 추가 해주시면 됩니다. 

<가로 고정>

AndroidManifest.xml


android:screenOrientation="portrait"


해당엑티비티.java

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);



<세로 고정>

AndroidManifest.xml


android:screenOrientation="landscape"

해당엑티비티.java

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);



이해를 돕기 위해서 가로로 고정하는 방법을 그림을 통해 보여 드리겠습니다. 

1. 가로로 화면 고정하기 

1.1 AndroidManifest.xml 소스보기를 해서 해당 Activity에 코드를 삽입합니다.

 

 

 

 

 


1.2 해당엑티비티.java 파일에 다음 코트를 넣습니다.

 

 

 

 

 


1.3 실행 후 화면이 가로로 고정된 것을 보실 수 있습니다.

 

 

 

 

 



※ 참고로 에뮬레이터에서 화면 돌리기 단축키는 Ctrl + F12 입니다.




=================================

=================================

=================================

 

 

 

 

반응형

 

728x90

 

 

 

 

안드로이드에서 가로 나 세로 모드로 고정하고싶을때 사용하는데

AndroidMenifest.xml 에서 <activity> 에 android:screenOrientation="portrait" 을 입력해 세로모드 고정.

가로 모드 고정은 "landscape" 이다.

 
출처 : http://blog.naver.com/loadtodream?Redirect=Log&logNo=30085733252


android에서 어떤 경우 화면을 가로, 세로로 유지해야 할 경우가 생기는데 이때 처리 하는 방법이다.

 

화면을 가로 또는 세로로 유지 하기 위해서는 "AndroidManifest.xml"를 수정하여 처리 할 수 있다.

 

1) 화면은 세로로 유지 하기.

<activity android:name=".(class이름)"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait">

 

2) 화면을 가로로 유지하기

<activity android:name=".( class 이름)"

                  android:label="@string/app_name"
                  android:screenOrientation="landscape">

 

이렇게 하면 그 클래스로 관리하는 화면이 고정이 된다.

 

[출처] Tip 4) Android 화면 고정|작성자 블루파츠

 

 

=================================

=================================

=================================

 

 

출처: http://www.androidside.com/bbs/board.php?bo_table=B46&wr_id=663

안녕하세요 ~

 가입한지는 꽤 됐는데 이제야 첫 글을 작성하는군요..

 별로 도움이 될진 모르겠지만 게임을 만들때 꼭 알아두어야할 팁 몇자 적어봅니다.

 일단 G1폰이 없으시다면 에뮬레이터에서 Crtl + F11 누르면 가로,세로 모드 전환 되는건

다들 아실거라 생각됩니다.

 문제는 이게 전환될 때 Activity 종료시켰다 다시 실행하고 레이아웃이 바뀌게 되죠.

 화면전환 이벤트가 발생해도 무시하고 화면을 고정시키는 방법을 알려드립니다.

 Activity 를 상속받은 클래스에서 onCreate() 안에 super.onCreate() 전에 다음 함수를 실행

시켜주면 간단하게 고정이됩니다.

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

 
이렇게만 해주시면 간단하게 고정이 됩니다. 이걸 찾으려고 몇일을 찾아해맸죠 영어가

딸려서 ㅡㅡ;

 또 다른 한가지는 제목표시줄과 상태표시줄 없애는 방법입니다.

 setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);

 
같은 위치에 작성해 주시면 됩니다.

 네? 모두 알고 계신 거라구요? 

 혹시나 저처럼 고생하는 사람이 있을까봐 올려봤습니다.

 감사합니다. 모두 열공하세요. 

 

=================================

=================================

=================================

 

 



위 글에 화면고정하는 방법은 고정은 되는데 액티비티는 다시 시작하는군요.. 
저 방법대신 
AndroidManifest.xml 을 수정시하시는 것이 더 좋을거 같습니다. 
<activity  android:screenOrientation="landscape" 
              android:configChanges="keyboardHidden|orientation"> 
이런식으루..  
sample 소스 snake에 있었군요 ㅡㅡ; 



 

=================================

=================================

=================================

 

 

 

This article describes how to force the orientation of an Android view not to change ie screen not to rotate.

 

How to lock the orientation

In the onCreateDialog(int) event of the activity use the setRequestedOrientation(int) method to set the screen orientation to your chosen setting. The activity will stay in this orientation regardless of if the device is tilted or not.

[Code sample – How to lock the orientation]
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}

 

How to detect the current orientation

To programmatically detect the current orientation of the activity use the following code snippet. The orientation property of theConfiguration class returns three possible values corresponding to Landscape, Portrait and Square.

[Code sample – How to detect the current orientation]
switch (this.getResources().getConfiguration().orientation)
{
case Configuration.ORIENTATION_PORTRAIT:
  // Do something here
  break;
case Configuration.ORIENTATION_LANDSCAPE:
  // Do something here
  break;
case Configuration.ORIENTATION_SQUARE:
  // Do something here
  break;
default:
  throw new Exception("Unexpected orientation enumeration returned");
  break;
}

 

Example : Locking rotation while performing an action.

You might wish to disable the screen rotation whilst performing an action or by user command, to do this you need to combine the above samples to detect the current orientation and lock the display to that orientation.

[Code sample – Locking rotation while performing an action]
// Sets screen rotation as fixed to current rotation setting
private void mLockScreenRotation()
{
  // Stop the screen orientation changing during an event
    switch (this.getResources().getConfiguration().orientation)
    {
  case Configuration.ORIENTATION_PORTRAIT:
    this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    break;
  case Configuration.ORIENTATION_LANDSCAPE:
    this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    break;
    }
}

Once your action has completed you may wish to enable screen rotation again, see the next section for an example on how to do this.

 

How to re-enable screen rotation

To enable the orientation to be automatically changed on device tilt simply pass the setRequestedOrientation(int) method the enumeration value for an unspecified orientation.

[Code sample – How to re-enable screen rotation]      
// allow screen rotations again
this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);


//

Have you tried writing the value of 
this.getResources().getConfiguration().orientation 
to LogCat? 

If this is some other value than ORIENTATION_PORTRAIT or ORIENTATION_LANDSCAPE then you may want to add a further case to the switch statement.
 
wbu 8th March 2011
Do you know how to make it work with SCREEN_ORIENTATION_REVERSE_LANDSCAPE and SCREEN_ORIENTATION_REVERSE_PORTRAIT too? What i am missing is a mapping of the Surface.ORIENTATION_XXX to the ActivityInfo.SCREEN_ORIENTATION_XXX depending on the devices "natural" orientation.
 
yongrak0 20th April 2011
@wbu, Unfortunately, that REVERSE things are supported after 2.3 android version. There's no way to lock reversed screen.
 
anthony 3rd June 2011
For all directions you can use int rotation = this.getWindowManager().getDefaultDisplay().getRotation(); this.setRequestedOrientation(rotation);



=================================

=================================

=================================

 

 

반응형


관련글 더보기

댓글 영역