3

我有一个活动,当我改变方向时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" />
4

1 回答 1

18

如果您的目标是API 13或更高,则必须添加。请screenSize更改此行:

android:configChanges="orientation|keyboardHidden"

android:configChanges="orientation|screenSize|keyboardHidden"
于 2013-07-08T12:40:50.733 回答