symbian九宫格问题
根据别人例子编写的symbian九宫格界面,怎么更改图标大小,在模拟器上看起来图片太小,在5802真机上测试更小,怎么设置图标大小,小弟刚接触symbian方面的知识,在网上也狂找了几天,还是没得解决,希望大虾们给小弟看看。运行效果如下:
代码如下
// -----------------------------------------// CThreeViewContainer::SetGridInitialParameters()// Sets initial parameters for grid// -----------------------------------------//void CGYYX_ProjectAppView::SetGridInitialParametersL() { TSize mpSize; // 主窗体大小 AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EMainPane, mpSize); iNumOfItems = 9; iNumOfColumns = KGridColumnCounts; // 列数 iNumOfRows = KGridRowsCounts; // 行数 // 计算出每个单元格的宽度和高度 iSizeOfCell.iWidth = mpSize.iWidth / iNumOfColumns-10; iSizeOfCell.iHeight = mpSize.iHeight / iNumOfRows; KGraphicsHeight = mpSize.iWidth / iNumOfColumns * 2 / 4; //图片的大小 // 滚动类型 iVerticalScrollingType = CAknGridView::EScrollIncrementLineAndLoops; iHorizontalScrollingType = CAknGridView::EScrollIncrementLineAndLoops; iVerticalOrientation = EFalse; iLeftToRight = ETrue; iTopToBottom = ETrue; // Set grid layout iGrid->SetLayoutL(iVerticalOrientation, iLeftToRight, iTopToBottom, iNumOfColumns, iNumOfRows, iSizeOfCell); // Set scrolling type iGrid->SetPrimaryScrollingType(iVerticalScrollingType); iGrid->SetSecondaryScrollingType(iHorizontalScrollingType); // Set current index in grid iGrid->SetCurrentDataIndex(0); }void CGYYX_ProjectAppView::CreateGridResourceL() { // Load graphics LoadGraphicsL(); // Create data AddDataL(); }void CGYYX_ProjectAppView::LoadGraphicsL() { // Create icon array with granularity of 1 icon CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray(iNumOfItems); CleanupStack::PushL(icons); TFullName fn; // 存储mbm文件的完整路径 TParsePtrC _parser(CEikonEnv::Static()->EikAppUi()->Application()->AppFullName()); fn.Append(_parser.Drive()); fn.Append(_L("\\resource\\apps\\GYYX_Project.mbm")); for (TInt i = 0; i < iNumOfItems; i++) { CGulIcon* icon; icon = iEikonEnv->CreateIconL(fn, i, i + 9); //icon = iEikonEnv->CreateIconL(fn, EMbmTest30001+i, EMbmTest30001+i + 9); icons->AppendL(icon); } iGrid->ItemDrawer()->ColumnData()->SetIconArray(icons); CleanupStack::Pop(icons); }void CGYYX_ProjectAppView::AddDataL() { MDesCArray* array = iGrid->Model()->ItemTextArray(); CDesCArray* cArray = (CDesCArray*) array; // The number of items in the grid. for (TInt loop = 0; loop < iNumOfItems; loop++) { TBuf<32> sBuf; sBuf.Format(_L("%d\tHuGe%d"), loop, loop); cArray->AppendL(sBuf); } // Inform list box that data was added. iGrid->HandleItemAdditionL(); }void CGYYX_ProjectAppView::ConstructL(const TRect& aRect) { // Create a window for this application view CreateWindowL(); iViewId = 1; // Create CAknGrid instance: iGrid = new (ELeave) CAknGrid; //Set the container window for grid control iGrid->SetContainerWindowL(*this); //Create a model and attach it to grid control: iGridM = new (ELeave) CAknGridM; iGrid->SetModel(iGridM); //Call ConstructL for the grid object: TInt gridFlags = EAknListBoxSelectionGrid; iGrid->ConstructL(this, gridFlags); // Set observer iGrid->SetListBoxObserver(this); // Set initial parameters for the grid SetGridInitialParametersL(); //Sets text to empty grid SetEmptyTextL(); // Create resouce for grid CreateGridResourceL(); // Set the windows size SetRect(aRect); // Activate the window, which makes it ready to be drawn ActivateL(); }CGYYX_ProjectAppView::~CGYYX_ProjectAppView() { // No implementation required if (iGrid) { delete iGrid; iGrid = NULL; } }CCoeControl* CGYYX_ProjectAppView::ComponentControl(TInt aIndex) const { switch ( aIndex ) { case 0: return iGrid; default: return NULL; } }void CGYYX_ProjectAppView::SizeChanged() { if (iGrid) { // Set initial parameters for the grid TRAP_IGNORE( SetGridInitialParametersL() ); //Apply the layout to cells in the grid ApplySelGridGraphicStyle(); iGrid->SetRect(Rect()); } }void CGYYX_ProjectAppView::ApplySelGridGraphicStyle() { //设置网格默认的前景色和背景色 AknListBoxLayouts::SetupStandardGrid( *iGrid ); //获取中文字体 const CFont* fontText = ApacPlain12(); //或者 const CFont* fontText = LatinBold12() TInt nX = (iGrid->ColumnWidth() - KGraphicsHeight) / 2; TInt nY = (iGrid->ItemHeight() - KGraphicsHeight - fontText->HeightInPixels()) / 2; //设置图标的布局 AknListBoxLayouts::SetupFormGfxCell( *iGrid, iGrid->ItemDrawer(), 0, //图标在网格项格式串中的位置,0表示第一项 nX, //左边位置 nY, //右边位置 0, //该参数无效 0, //该参数无效 KGraphicsHeight, // Width KGraphicsHeight, // Height TPoint( nX, nY ), //图标左顶点的相对坐标 TPoint( KGraphicsHeight+nX, KGraphicsHeight+nY) ); //图标右底点的相对坐标 //设置文本的布局 AknListBoxLayouts::SetupFormAntiFlickerTextCell( *iGrid, iGrid->ItemDrawer(), 1, //文本在网格项格式串中的位置 fontText, //字体 0, //文本颜色(215是系统调色板中黑色对应的索引值) 0, //左边空白 0, //该参数无效 KGraphicsHeight+nY+fontText->HeightInPixels(), //基线 iGrid->ColumnWidth(), //文本的宽度 CGraphicsContext::ECenter, //文本对齐方式,居中 TPoint( 0, KGraphicsHeight+nY), //文本左顶点的相对坐标 TPoint( iGrid->ColumnWidth(), iGrid->ItemHeight()) ); //文本右底点的相对坐标 }void CGYYX_ProjectAppView::ProcessUserKeyEventL() { /* * 要做的工作,先获取当然选中的菜单项,再判断此菜单项是否有子菜单项, * 如果有,则显示第二级九宫格,如果没有,则显示功能菜单 */ //CTextListBoxModel* iTextModel = iGrid->Model(); //CDesCArray* iCArray = static_cast<CDesCArray*>(iTextModel->ItemTextArray()); //TInt index = iGrid->CurrentItemIndex() ; //执行相应的菜单命令...暂时用对话框代替 CAknGlobalNote* glbNote = CAknGlobalNote::NewLC(); glbNote->ShowNoteL(EAknGlobalInformationNote ,_L("nihao")); CleanupStack::PopAndDestroy(); }void CGYYX_ProjectAppView::SetIconSizes( CArrayPtr<CGulIcon>* aIconArray ) { TSize iconSize; iconSize.iWidth = iSizeOfCell.iWidth; // / 2; iconSize.iHeight = iSizeOfCell.iHeight; // / 2; if(aIconArray->Count() > 0) AknIconUtils::SetSize( (*aIconArray)[0]->Bitmap(), iconSize ); }// End of File
void CGYYX_ProjectAppView::SetIconSizes( CArrayPtr<CGulIcon>* aIconArray ) { TSize iconSize; iconSize.iWidth = 100; // / 2; iconSize.iHeight = 100; // / 2; if(aIconArray->Count() > 0) AknIconUtils::SetSize( (*aIconArray)[0]->Bitmap(), iconSize ); }
[解决办法]
顶. 同求如何九宫格显示汉字 Huge 改为汉字