当前位置: 代码迷 >> Android >> Android Launcher 怎么实现壁纸居中
  详细解决方案

Android Launcher 怎么实现壁纸居中

热度:109   发布时间:2016-04-28 05:41:52.0
Android Launcher 如何实现壁纸居中

前言
         欢迎大家我分享和推荐好用的代码段~~
声明
         欢迎转载,但请保留文章原始出处:
         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);
                    }
                }
            }
        }
 

  相关解决方案