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