Launcher2折腾之路(1)

想自己写一个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;
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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可夫小子

感谢大佬!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值