Android Launcher3 修改行数和列数

简介: Android Launcher3 修改行数和列数

packages\apps\Launcher3\src\com\android\launcher3\InvariantDeviceProfile.java

    ArrayList<InvariantDeviceProfile> getPredefinedDeviceProfiles(Context context) {
        ArrayList<InvariantDeviceProfile> profiles = new ArrayList<>();
        try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
            final int depth = parser.getDepth();
            int type;
 
            while (((type = parser.next()) != XmlPullParser.END_TAG ||
                    parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
                if ((type == XmlPullParser.START_TAG) && "profile".equals(parser.getName())) {
                    TypedArray a = context.obtainStyledAttributes(
                            Xml.asAttributeSet(parser), R.styleable.InvariantDeviceProfile);
                    int numRows = a.getInt(R.styleable.InvariantDeviceProfile_numRows, 0);
                    int numColumns = a.getInt(R.styleable.InvariantDeviceProfile_numColumns, 0);
                    float iconSize = a.getFloat(R.styleable.InvariantDeviceProfile_iconSize, 0);
                    profiles.add(new InvariantDeviceProfile(
                            a.getString(R.styleable.InvariantDeviceProfile_name),
                            a.getFloat(R.styleable.InvariantDeviceProfile_minWidthDps, 0),
                            a.getFloat(R.styleable.InvariantDeviceProfile_minHeightDps, 0),
                            numRows,
                            numColumns,
                            a.getInt(R.styleable.InvariantDeviceProfile_numFolderRows, numRows),
                            a.getInt(R.styleable.InvariantDeviceProfile_numFolderColumns, numColumns),
                            iconSize,
                            a.getFloat(R.styleable.InvariantDeviceProfile_landscapeIconSize, iconSize),
                            a.getFloat(R.styleable.InvariantDeviceProfile_iconTextSize, 0),
                            a.getInt(R.styleable.InvariantDeviceProfile_numHotseatIcons, numColumns),
                            a.getResourceId(R.styleable.InvariantDeviceProfile_defaultLayoutId, 0),
                            a.getResourceId(R.styleable.InvariantDeviceProfile_demoModeLayoutId, 0)));
                    a.recycle();
                }
            }
        } catch (IOException|XmlPullParserException e) {
            throw new RuntimeException(e);
        }
        return profiles;
    }


从R.xml.device_profiles这个文件中读取数据


packages\apps\Launcher3\res\xml\device_profiles.xml


<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2016 The Android Open Source Project
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0
 
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
 
<profiles xmlns:launcher="http://schemas.android.com/apk/res-auto" >
 
    <profile
        launcher:name="Super Short Stubby"
        launcher:minWidthDps="255"
        launcher:minHeightDps="300"
        launcher:numRows="2"
        launcher:numColumns="3"
        launcher:numFolderRows="2"
        launcher:numFolderColumns="3"
        launcher:iconSize="48"
        launcher:iconTextSize="13.0"
        launcher:numHotseatIcons="3"
        launcher:defaultLayoutId="@xml/default_workspace_3x3"
        />
 
    <profile
        launcher:name="Shorter Stubby"
        launcher:minWidthDps="255"
        launcher:minHeightDps="400"
        launcher:numRows="3"
        launcher:numColumns="3"
        launcher:numFolderRows="3"
        launcher:numFolderColumns="3"
        launcher:iconSize="48"
        launcher:iconTextSize="13.0"
        launcher:numHotseatIcons="3"
        launcher:defaultLayoutId="@xml/default_workspace_3x3"
        />
 
    <profile
        launcher:name="Short Stubby"
        launcher:minWidthDps="275"
        launcher:minHeightDps="420"
        launcher:numRows="3"
        launcher:numColumns="4"
        launcher:numFolderRows="3"
        launcher:numFolderColumns="4"
        launcher:iconSize="48"
        launcher:iconTextSize="13.0"
        launcher:numHotseatIcons="5"
        launcher:defaultLayoutId="@xml/default_workspace_4x4"
        />
 
    <profile
        launcher:name="Stubby"
        launcher:minWidthDps="255"
        launcher:minHeightDps="450"
        launcher:numRows="3"
        launcher:numColumns="4"
        launcher:numFolderRows="3"
        launcher:numFolderColumns="4"
        launcher:iconSize="48"
        launcher:iconTextSize="13.0"
        launcher:numHotseatIcons="5"
        launcher:defaultLayoutId="@xml/default_workspace_4x4"
        />
 
    <profile
        launcher:name="Nexus S"
        launcher:minWidthDps="296"
        launcher:minHeightDps="491.33"
        launcher:numRows="4"
        launcher:numColumns="4"
        launcher:numFolderRows="4"
        launcher:numFolderColumns="4"
        launcher:iconSize="48"
        launcher:iconTextSize="13.0"
        launcher:numHotseatIcons="5"
        launcher:defaultLayoutId="@xml/default_workspace_4x4"
        />
 
    <profile
        launcher:name="Nexus 4"
        launcher:minWidthDps="359"
        launcher:minHeightDps="567"
        launcher:numRows="4"
        launcher:numColumns="4"
        launcher:numFolderRows="4"
        launcher:numFolderColumns="4"
        launcher:iconSize="54"
        launcher:iconTextSize="13.0"
        launcher:numHotseatIcons="5"
        launcher:defaultLayoutId="@xml/default_workspace_4x4"
        />
 
    <profile
        launcher:name="Nexus 5"
        launcher:minWidthDps="335"
        launcher:minHeightDps="567"
        launcher:numRows="4"
        launcher:numColumns="4"
        launcher:numFolderRows="4"
        launcher:numFolderColumns="4"
        launcher:iconSize="54"
        launcher:iconTextSize="13.0"
        launcher:numHotseatIcons="5"
        launcher:defaultLayoutId="@xml/default_workspace_4x4"
        />
 
    <profile
        launcher:name="Large Phone"
        launcher:minWidthDps="406"
        launcher:minHeightDps="694"
        launcher:numRows="5"
        launcher:numColumns="5"
        launcher:numFolderRows="4"
        launcher:numFolderColumns="4"
        launcher:iconSize="56"
        launcher:iconTextSize="14.4"
        launcher:numHotseatIcons="5"
        launcher:defaultLayoutId="@xml/default_workspace_5x5"
        />
 
    <profile
        launcher:name="Nexus 7"
        launcher:minWidthDps="575"
        launcher:minHeightDps="904"
        launcher:numRows="6"
        launcher:numColumns="6"
        launcher:numFolderRows="4"
        launcher:numFolderColumns="5"
        launcher:iconSize="64"
        launcher:iconTextSize="14.4"
        launcher:numHotseatIcons="6"
        launcher:defaultLayoutId="@xml/default_workspace_5x6"
        />
 
    <profile
        launcher:name="Nexus 10"
        launcher:minWidthDps="727"
        launcher:minHeightDps="1207"
        launcher:numRows="6"
        launcher:numColumns="7"
        launcher:numFolderRows="4"
        launcher:numFolderColumns="5"
        launcher:iconSize="76"
        launcher:iconTextSize="14.4"
        launcher:numHotseatIcons="7"
        launcher:defaultLayoutId="@xml/default_workspace_5x6"
        />
 
    <profile
        launcher:name="20-inch Tablet"
        launcher:minWidthDps="1527"
        launcher:minHeightDps="2527"
        launcher:numRows="7"
        launcher:numColumns="7"
        launcher:numFolderRows="6"
        launcher:numFolderColumns="6"
        launcher:iconSize="100"
        launcher:iconTextSize="20.0"
        launcher:numHotseatIcons="7"
        launcher:defaultLayoutId="@xml/default_workspace_5x6"
        />
 
</profiles>

根据屏幕尺寸设置不同的布局

修改 numHotseatIcons的数量即可


目录
相关文章
|
Android开发
Android 7.1 Launcher3 删除主页搜索框
Android 7.1 Launcher3 删除主页搜索框
478 0
Android 7.1 Launcher3 删除主页搜索框
|
Android开发
Android 7.1 Launcher3 支持按键操作显示所有应用
Android 7.1 Launcher3 支持按键操作显示所有应用
573 0
Android 7.1 Launcher3 支持按键操作显示所有应用
|
Android开发
android12.0(S) Launcher3 细节修改
android12.0(S) Launcher3 细节修改
718 0
|
API 数据库 Android开发
Android M Launcher3主流程源码浅析
背景 关于Launcher是啥的问题我想这里就没必要再强调了。由于一些原因迫使最近开始需要研究一下Launcher3源码,为了不再像以前那么傻逼(研究Settings等代码没作笔记),故这里赶紧将阶段性的感悟整理成文章,方便日后回看。
2034 0
|
8月前
|
移动开发 前端开发 Android开发
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
1529 12
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
8月前
|
移动开发 JavaScript 应用服务中间件
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
1062 5
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
8月前
|
移动开发 Rust JavaScript
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
1146 4
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
9月前
|
开发工具 Android开发
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
900 11
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡

热门文章

最新文章