Android Launcher 如何实现壁纸居中

时间:2014-05-13 14:25:56   收藏:0   阅读:384

前言
         欢迎大家我分享和推荐好用的代码段~~
声明
         欢迎转载,但请保留文章原始出处:
         CSDN:
http://www.csdn.net
         雨季o莫忧离:http://blog.csdn.net/luckkof

正文

 

KK Launcher3的wallpaper显示是动态的,与Launcher预置桌面数目有关,让壁纸居中,只能确保第一次开机时壁纸居中,后面用户修改桌面数目后,就无法达到了。如何要在默认桌面数目配置时居中,可以参考下面方法,以default一屏为例:
Launcher3的workspace.java文件替换下面的函数
private void updateOffset(boolean force) {
            if (mWaitingForUpdate || force) {
                mWaitingForUpdate = false;
    LauncherLog.d(TAG, "updateOffset: mWallpaperOffset = " + mWallpaperOffset.getCurrX());
                if (computeScrollOffset() && mWindowToken != null) {
                    try {
       if (getChildCount() <= 1) {
           LauncherLog.d(TAG, "wallpaperOffset 111");
                 mWallpaperManager.setWallpaperOffsets(mWindowToken,
                               /* mWallpaperOffset.getCurrX()*/0.5f, 0.5f);
         }else{
                             LauncherLog.d(TAG, "wallpaperOffset 222");
                             mWallpaperManager.setWallpaperOffsets(mWindowToken,
                               mWallpaperOffset.getCurrX(), 0.5f);
             }
                        setWallpaperOffsetSteps();
                    } catch (IllegalArgumentException e) {
                        Log.e(TAG, "Error updating wallpaper offset: " + e);
                    }
                }
            }
        }
 

Android Launcher 如何实现壁纸居中,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!