想自己写一个Launcher,但无从下手,那就从Launcher2源码开刀吧。一味的看源码也不是个事,那就自己动手折腾,修改Launcher来加深对Launcher的理解。
1,把work_space中的cell默认是5个,要整成1个。我的屏幕的size是720P-50hz,对应的Layout文件夹是layout-sw720dp/。我也不知道怎么对应上的,一个一个试的。——!!!
1 | - static final int SCREEN_COUNT = 5; |
2 | - static final int DEFAULT_SCREEN = 2; |
3 | + static final int SCREEN_COUNT = 1;//5; |
4 | + static final int DEFAULT_SCREEN =0;// 2; |
5 | WorkSpace.Java |
1 | --- a/res/layout-sw720dp/launcher.xml |
2 | +++ b/res/layout-sw720dp/launcher.xml |
3 | @@ -57,7 +57,7 @@ |
4 | android:paddingEnd="@dimen/workspace_right_padding" |
5 | android:paddingTop="@dimen/workspace_top_padding" |
6 | android:paddingBottom="@dimen/workspace_bottom_padding" |
7 | - launcher:defaultScreen="2" |
8 | + launcher:defaultScreen="0" |
9 | launcher:cellCountX="@integer/cell_count_x" |
10 | launcher:cellCountY="@integer/cell_count_y" |
11 | launcher:pageSpacing="@dimen/workspace_page_spacing" |
12 | @@ -65,10 +65,10 @@ |
13 | launcher:scrollIndicatorPaddingRight="@dimen/workspace_divider_padding_right"> |
14 | |
15 | <include android:id="@+id/cell1" layout="@layout/workspace_screen" /> |
16 | - <include android:id="@+id/cell2" layout="@layout/workspace_screen" /> |
17 | + <!-- <include android:id="@+id/cell2" layout="@layout/workspace_screen" /> |
18 | <include android:id="@+id/cell3" layout="@layout/workspace_screen" /> |
19 | <include android:id="@+id/cell4" layout="@layout/workspace_screen" /> |
20 | - <include android:id="@+id/cell5" layout="@layout/workspace_screen" /> |
21 | + <include android:id="@+id/cell5" layout="@layout/workspace_screen" /> --> |
22 | </com.android.launcher2.Workspace> |
23 |
2,APPS_CUSTOMIZE界面的Icon后面加背景图片
1 | if (true) |
2 | { |
3 | Bitmap backBitmap = BitmapFactory.decodeResource(context.getResources(), |
4 | R.drawable. icon_back); |
5 | int backWidth = backBitmap.getWidth(); |
6 | int backHeight = backBitmap.getHeight(); |
7 | Log. i(Launcher.TAG,"koffu pic width=" + backWidth + ", width=" + backHeight); |
8 | Log. i(Launcher .TAG ,"koffu sIconwidth=" + sIconWidth + ", sIconHeight=" + sIconHeight); |
9 | if(backWidth != sIconWidth || backHeight != sIconHeight) |
10 | { |
11 | Matrix matrix = new Matrix(); |
12 | matrix.postScale((float)sIconWidth /backWidth, (float)sIconHeight /backHeight); |
13 | canvas.drawBitmap(Bitmap.createBitmap(backBitmap, 0, 0, backWidth, backHeight, matrix, true ), |
14 | 0.0f, 0.0f, null); |
15 | } else |
16 | { |
17 | canvas.drawBitmap(backBitmap, 0.0f, 0.0f, null); |
18 | } |
19 | } |
20 |
效果如下(每个icon后面都有一个熊孩子图片):
稍微延伸一下:
Canvas/Bitmap/Matrix这三个类的关系
Bitmap这个类主要是用来“获取”“承装”位置的类
Canvas这个类主要是用来“绘制”位图的类
Matrix这个类主要是用来“缩放”“旋转”的类
具体可以参考:http://www.cnblogs.com/feisky/archive/2010/01/10/1643460.html