Android8.1 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),
a.getInt(R.styleable.InvariantDeviceProfile_minAllAppsPredictionColumns, 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这个文件中读取数据,搜了一下,发现有两个文件:
./go/res/xml/device_profiles.xml
./res/xml/device_profiles.xml
经过验证,调用的是./go/res/xml/device_profiles.xml,至于为啥是这个没搞清楚;
好了,话不多说,直接上代码:
<!--<profile
launcher:name="Go Device"
launcher:minWidthDps="296"
launcher:minHeightDps="491.33"
launcher:numRows="4"
launcher:numColumns="4"
launcher:numFolderRows="4"
launcher:numFolderColumns="4"
launcher:iconSize="60"
launcher:iconTextSize="14.0"
launcher:defaultLayoutId="@xml/default_workspace_4x4"
/>
-->
<profile
launcher:name="Go Device"
launcher:minWidthDps="296"
launcher:minHeightDps="491.33"
launcher:numRows="7"
launcher:numColumns="5"
launcher:numFolderRows="4"
launcher:numFolderColumns="4"
launcher:iconSize="48"
launcher:iconTextSize="12.0"
launcher:defaultLayoutId="@xml/default_workspace_4x4"
/>
我这里是把numColumns改为5,numRows改为7,iconTextSize改为12;
运行一下,果断生效;
现在我们的Launcher看起来比之前已经好多了