Android:onConfigurationChanged()没有调用Orientation中的更改

时间:2013-07-08 12:38:48

标签: android

我有一项活动,当我更改方向时,不会调用onConfigurationChanged()

请帮我解决这个问题。我试过但找不到原因。

代码:

@Override
public void onConfigurationChanged(Configuration configure){
    super.onConfigurationChanged(configure);
    setLayout(); //Set the layout.

    //Get the orientation of the device and set the gravity according to that.
    if(configure.orientation == Configuration.ORIENTATION_PORTRAIT) {
        parentLinearLayout.setGravity(Gravity.CENTER_VERTICAL);
    } else if(configure.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        parentLinearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
    }
}

<activity android:name=".AddProductsActivity" 
    android:configChanges="orientation|keyboardHidden"/>

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

1 个答案:

答案 0 :(得分:18)

如果您定位API 13或更高,则必须添加screenSize。请更改此行:

android:configChanges="orientation|keyboardHidden"

android:configChanges="orientation|screenSize|keyboardHidden"