监听屏幕布局的变化

来源:互联网 发布:手机淘宝客户端 html5 编辑:程序博客网 时间:2024/05/01 00:04

CS001438

 开发伙伴平台:
S60 3rd Edition, S60 5th Edition

 详细描述
当屏幕的尺寸或方位发生变化时,系统就会产生布局和屏幕方位改变的事件。S60平台支持多个屏幕分辨率,这个事件可以通过程序的CAknAppUi类或程序的CCoeControl控件处理。
 源代码
解决方案1:
派生自CCoeControl的控件可以通过重载CCoeControl::HandleResourceChange()方法来获取布局的改变通知:
void CExampleControl::HandleResourceChange(TInt aType)
        {
        // Call base class implementation
        CCoeControl::HandleResourceChange(aType);
        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);
              // Set new screen rect
              SetRect(rect);
              }
        }
解决方案2:
从CAknAppUi派生的Application UI类可以重载CEikAppUi::HandleResourceChangeL()方法,以便获得KEikDynamicLayoutVariantSwitch的布局改变通知
void CExampleAppUi::HandleResourceChangeL(TInt aType)
        {
        // Call base class implementation
        CAknAppUi::HandleResourceChangeL( aType );
        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);
 
              // Set new screen rect
              // Must not call this if the iExampleControlContainer
              // component is on the control stack
              iExampleControlContainer->SetRect(rect);
             }
 
        // Must not call this if the iSomeDialog
        // component is on the control stack
        //iSomeDialog->HandleResourceChangeL( aType );
        }

 相关资料
TSS001178 - Switching orientation in dialog-based applications

 

原创粉丝点击