Launcher2折腾之路(1)

来源:互联网 发布:林白的过程解析知乎 编辑:程序博客网 时间:2024/06/05 08:41

想自己写一个Launcher,但无从下手,那就从Launcher2源码开刀吧。一味的看源码也不是个事,那就自己动手折腾,修改Launcher来加深对Launcher的理解。

1,把work_space中的cell默认是5个,要整成1个。我的屏幕的size是720P-50hz,对应的Layout文件夹是layout-sw720dp/。我也不知道怎么对应上的,一个一个试的。——!!!

-    static final int SCREEN_COUNT = 5;-    static final int DEFAULT_SCREEN = 2;+    static final int SCREEN_COUNT = 1;//5;+    static final int DEFAULT_SCREEN =0;// 2; 5  WorkSpace.Java

 

--- a/res/layout-sw720dp/launcher.xml+++ b/res/layout-sw720dp/launcher.xml@@ -57,7 +57,7 @@             android:paddingEnd="@dimen/workspace_right_padding"             android:paddingTop="@dimen/workspace_top_padding"             android:paddingBottom="@dimen/workspace_bottom_padding"-            launcher:defaultScreen="2"+            launcher:defaultScreen="0"             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后面加背景图片

if (true)            {                Bitmap backBitmap = BitmapFactory.decodeResource(context.getResources(),                        R.drawable. icon_back);                int backWidth = backBitmap.getWidth();                int backHeight = backBitmap.getHeight();                Log. i(Launcher.TAG,"koffu pic width=" + backWidth + ", width=" + backHeight);                Log. i(Launcher .TAG ,"koffu sIconwidth=" + sIconWidth + ", sIconHeight=" + sIconHeight);                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后面都有一个熊孩子图片):

image

稍微延伸一下:

Canvas/Bitmap/Matrix这三个类的关系
Bitmap这个类主要是用来“获取”“承装”位置的类
Canvas这个类主要是用来“绘制”位图的类
Matrix这个类主要是用来“缩放”“旋转”的类
具体可以参考:http://www.cnblogs.com/feisky/archive/2010/01/10/1643460.html

0 0
原创粉丝点击