Layout change events are generated when the screen size or layout is changed. The S60 platform supports multiple screen resolutions (scalable UI). Thus, layout awareness is particularly crucial for those applications that implement a customized UI instead of using automatically scalable Avkon UI components. Applications can detect the changes in layout with, for example, the following methods:
Controls can override the CCoeControl::HandleResourceChange()
to detect the KEikDynamicLayoutVariantSwitch
message.
UI controllers can override the CEikAppUi::HandleResourceChangeL()
to detect the KEikDynamicLayoutVariantSwitch
message.
The following example code demonstrates the implementation of HandleResourceChange()
:
void CExampleControl::HandleResourceChange(TInt aType) { CCoeControl::HandleResourceChange(aType); //call base class implementation if ( aType==KEikDynamicLayoutVariantSwitch ) { TRect rect; // ask where container's rectangle should be // EMainPane equals to area returned by //CEikAppUi::ClientRect() AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,rect); SetRect(rect); } }
The following example code demonstrates the implementation of HandleResourceChangeL()
:
void CExampleAppUi::HandleResourceChangeL(TInt aType) { CAknAppUi::HandleResourceChangeL( aType ); if ( aType == KEikDynamicLayoutVariantSwitch ) { // do the re-layout of the components } // Controls derived from CCoeControl, handled in a // container class iExampleControlContainer->HandleResourceChange( aType ); //Must not call this if the components are on the control stack //iView->HandleResourceChangeL( aType ); }
If iExampleControlContainer
is added to the control
stack, it will get its HandleResourceChange()
called
when a layout is switched and there is no need to call it explicitly.
For a reference design of a layout-aware application using a custom UI, refer to the S60 Platform: Scalable Screen-Drawing Example available for download from Forum Nokia.