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:
- Whenever the device is in Lands开发者_如何转开发cape mode, the chart should be displayed.
- 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
- Override
Activity.onConfigurationChanged()
- but then what? Can i do asetContentView()
at this point? Or, can i launch a different Activity (one which displays the Chart in a separate, lanscape-mode-only Activity)? - Override
Application.onConfigurationChanged()
method. But I frankly haven't a clue as to how to proceed with this.
Yes you can call
setContentView()
insideActivity.onConfigurationChanged()
. You can check orientation and accordingly perform some tasks, i.e. run different code based on orientation.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 theonConfigurationChanged(..)
method, which will be called when change happens. See handling runtime changes.
精彩评论