开发者

Offering different _functionality_ (not merely layout) based on orientation?

I have a monitoring app that displays a set of four parameters as animations (for example, it displays the temperature using a thermometer graphic). I also have one screen which plots all the four parameter values on a chart.

My requirement is this:

  1. Whenever the device is in Lands开发者_如何转开发cape mode, the chart should be displayed.
  2. Whenever the device is back in portrait mode, the earlier animation screen should be displayed.

I'm wondering if it is possible to provide different functionality based on the orientation. I see 2 options

  1. Override Activity.onConfigurationChanged() - but then what? Can i do a setContentView() at this point? Or, can i launch a different Activity (one which displays the Chart in a separate, lanscape-mode-only Activity)?
  2. Override Application.onConfigurationChanged() method. But I frankly haven't a clue as to how to proceed with this.


  1. Yes you can call setContentView() inside Activity.onConfigurationChanged(). You can check orientation and accordingly perform some tasks, i.e. run different code based on orientation.

  2. Normal behaviour is that when orientation changes, system kills Activity and creates a new one. You can prevent this with android:configChanges="orientation" in you activity manifest. In this case you need to override the onConfigurationChanged(..) method, which will be called when change happens. See handling runtime changes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜