开发者

how to adjust the proper interface for both portrait and landscape mode for xml files in android

My problem is that I prepare my xml in portrait mode in Android but when I try to run the application with phone and get the landscape mode, my interface crash. Picture gets smaller and buttons don't appear on the screen. I want my interface to be the same whether the phone is in landscape mode or portrait mode. How can I solve this problem? Can I prepare two different xml for one class, one for landscape and the other for portrait mode or is there any other solution? Than开发者_开发问答ks


You have two options here. The first is to add the android:configChanges attribute to that activity in the manifest:

<activity android:name="the activity's class name" android:configChanges="orientation" >

This will stop android from recreating the activity when the orientation changes. Instead the activity's onConfigurationChanged method will be called.

The other is to make another layout that will be used when the device is in landscape. It would need to be named the same as the portrait layout and put under layout-land.

There's probably other options as well, these are just the ones that I know of.


You can easily have different layouts in different orientations, see "Screen Orientation" in Providing Resources

All you need to do is create a layout-port or layout-land directory under res, and put the alternate XML in there.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜