开发者

Android, Orientation Question with Tabhost and it's Very strange

everyone.

I have created a Tabhost and there are 4 buttons on it.

I set android:configChanges="orientation|keyboardHidden" on every Activity in the menifest file.

And I also override the onConfigurationChanged method to listen the event when the screen is oriented.

Now there is a "Bug", and I don't know how to solve it.

When I click on one of the 4 buttons(for example, A, B, C, and D), and I rotate the Tablet's orientation from portrait to landscape, the Activity is fine. Its onConfigurationChanged method w开发者_运维知识库orks.

But When I click the B button on landscape mode, its portrait state is still kept(I want B button's onConfigChanged method to be called, but it doesn't). In a word, if you changed the orientation, and you click another Tab button, the Activity's onConfigurationChanged method won't be called.

How can I solve this problem? Thanks a lot.


You cant call onConfigChanged() for a view or any kind of callback, it is called only from the device, as far as I know. I have no ideas besides this comment.


Try removing the line:

super.onConfigurationChanged(newConfig);

from your onConfigurationChanged() function. And if that doesn't do the trick please post what you open/what happens when you click any of the tabs so we can realize what might be causing the problem.


However, the best way to do what you are trying there is to put the drawables in the correct directories under your resources and use the same name for both. This way you wouldn't need to specify what drawable to use for the different configuration, but rather leave the android OS to do that for you. Put the one in the directory drawable and the other one in the drawable-land or drawable-port depending on the orientation of your default one. You could read more about how to provide resources and specify when they are used in here Providing Resources


Thanks for the replies. Now I finally know what's wrong with my program.

Because I were using the TabHost, when the screen orientation is changed, there are only two Activities' onConfigurationChanged method would be called.

For example, there is an Activity which is the container for TabHost. And there are other four Activities(A,B,C, and D) which are the parts of the TabHost Activity.

So when the screen orientation is changed with Activity A, only the TabHost and Activity A's onConfigurationChanged method would be called. The others will NOT be called.

That's why when the screen is changed from Portrait to Landscape. A's onConfiguration is changed, but when you click other tabs button, B,C, and D won't be changed(Still look like Portrait on Landscape mode).

So the answer is you have to control the configuration method on TabHost Activity. And now it works well.

If you are using Tabhost, you have to notice this.


I found a solution to a similar problem.

I'm using tabhost and want 3 of 4 tabs to be able to rotate and 1 tab set to portrait mode only. Previously (before applying this fix) the 3 tabs would rotate until the fixed portrait tab was selected, then they were all stuck in portrait mode.

I had to set the other tabs to use the orientation of the USER to remedy this. i.e. added a setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER); in the onResume of the other 3 tabs and it now works exactly as I had intended. 3 tabs will now rotate based on the user's orientation of the device, and 1 tab is fixed portrait. :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜