监听屏幕布局的变化

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值