Launcher App:\cupcake\packages\apps\Launcher
待機(jī)畫面分為多層,桌面Desktop Items在\res\layout-*\workspace_screen.xml中設(shè)置:
<com.android.launcher.CellLayout
... ...
launcher:shortAxisCells="4"
launcher:longAxisCells="4"
... ...
/>
表示4行4列
再看看 com.android.launcher.CellLayout ,其中有定義屏幕方向的參數(shù),
private boolean mPortrait;
但是一直沒有初始化,也就是mPortrait=false,桌面的單元格設(shè)置一直是以非豎屏(橫屏)的設(shè)置定義進(jìn)行初始化。
再來看看橫屏和豎屏情況下的初始化不同之處,就可以看出BUG了。
boolean[][] mOccupied;//二元單元格布爾值數(shù)組
if (mPortrait) {
mOccupied = new boolean[mShortAxisCells][mLongAxisCells];
} else {
mOccupied = new boolean[mLongAxisCells][mShortAxisCells];
}
如果我們滿屏顯示桌面(橫向和縱向的單元格數(shù)不一致),而不是默認(rèn)的只顯示4行4列,則mShortAxisCells = 4, mLongAxisCells = 5,數(shù)組應(yīng)該初始化是:new boolean[4][5],但是實(shí)際是按照非豎屏處理,初始化成了new boolean[5][4],會(huì)產(chǎn)生數(shù)組越界異常。
可以在構(gòu)造函數(shù)中,添加通過屏幕方向初始化mPortrait,代碼如下:
public CellLayout(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
mPortrait = this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;// 新增代碼
... ...
}
本文來自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/netpirate/archive/2009/06/05/4245445.aspx
posted on 2009-08-29 23:26
Xu Jianxiang 閱讀(623)
評(píng)論(0) 編輯 收藏 所屬分類:
Android