2012-11-19 2 views
0

두 레이아웃이 각각 layout-portlayout-land에 하나씩 정의 된 활동을 만들었습니다. 그들은 지금까지 잘 작동합니다.가로 방향이 변경된 상태에서 가로 모드가 호출되지 않습니다.

하지만 오리엔테이션이 변경되면 onCreate이 다시 호출되는 문제가 있습니다. 그래서 매니페스트 파일에 내가 지정했는지 android:configChanges="orientation" 속성을 방지하기 위해 내가 응용 프로그램을 실행할 때

@Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 

    } 

지금 활동에 다음과 같은 코드를 사용하고 짝수 세로 레이아웃을 사용하고 내가 안드로이드를 볼 수있는 실제 장치의 방향을 변경 장치를 기울이고 활동 상태를 변경하지 않습니다.

기본적으로 onCreate은 내가 원하는 것은 아니지만 장치가 기울어 진 경우 가로 모드를 사용하지 않습니다.

+1

http://stackoverflow.com/questions/8532614/onconfigurationchanged-is-not-being-called-on-orientation-change – Omarj

답변

0

android : configChanges = "orientation | screenSize"를 매니페스트의 활동에 추가하십시오.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.orientationchange" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="15" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/title_activity_main"    
      android:configChanges="orientation|screenSize"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 


import android.os.Bundle; 
import android.app.Activity; 
import android.content.res.Configuration; 
import android.widget.Toast; 

public class MainActivity extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    @Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 

     // Checks the orientation of the screen 
     if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { 
      Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); 
     } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ 
      Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); 
     } 
    } 
} 
+0

screenSize''난 로이드 3 higer 대한 추측 – Hunt

관련 문제