开发者

How can I change my view in horizontal orientation and then back to portrait?

I want my view to change when it has changed to horizontal orientation:

@Override
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(new开发者_如何学JAVAConfig);
      setContentView(R.layout.chartsactivity);
    }

This works, but I want my layout to switch back when it is in portrait mode.


To let the system handle the layout change you have to specify a special layout for landscape mode for the layout files you want to look different in landscape mode. This is done through a special folder for landscape layouts. Just put a layout-land folder in your resources folder. If your application is running in landscape mode, and such a folder is present the system will look for layout files in this folder first and if the layout is not found fall back to the standard layout folder.


Just look at the orientation of newConfig and use a different layout in each case? It would be much better if you let the system do it for you though.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜