开发者

View change with orientation change and preventing activity restart are not working together

开发者 https://www.devze.com 2023-02-25 08:34 出处:网络
I used following code to prevent activity from starting again when phone is rotated.. android:configChanges=\"keyboardHidden|orientation\"开发者_开发知识库

I used following code to prevent activity from starting again when phone is rotated..

android:configChanges="keyboardHidden|orientation"开发者_开发知识库

I used following format to get different views for horizontal and vertical displays...

For portrait mode xml in res/layout-port, and For landscape xml in res/layout-land

The problem is these codes dont work together.....


Use this: Create two views with the same name. Move one in res/layout and different in res/layout-land and add this code in your activity.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.main); 

            ..
}

"main" layout is gotten from res/layout-land when phone is land oriented and other "main" is gotten from res/layout when portrait oriented.


Use this

android:configChanges="orientation|keyboardHidden"

instead of

android:configChanges="keyboardHidden|orientation"

then it will work.

0

精彩评论

暂无评论...
验证码 换一张
取 消