Launcher修改--修改底部图标

本文介绍如何在Android 2.2系统的Launcher中移除底部预设的电话和浏览器图标,并提供了具体的XML布局文件及Java代码修改方法。

在android2.2中,launcher的底部被修改成这种模式,有时候修改launcher的时候需要去掉电话和浏览器两项,我们可以在res/layout-port/文件夹中找到launcher.xml文件,在其中有以下代码

<RelativeLayout android:id="@+id/all_apps_button_cluster" android:layout_width="fill_parent" android:layout_height="@dimen/button_bar_height" android:layout_gravity="bottom|center_horizontal" android:paddingTop="2dip" > <com.android.launcher2.HandleView style="@style/HotseatButton" android:id="@+id/all_apps_button" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:src="@drawable/all_apps_button" launcher:direction="horizontal" /> <ImageView android:id="@+id/hotseat_left" style="@style/HotseatButton.Left" android:layout_toLeftOf="@id/all_apps_button" android:src="@drawable/hotseat_phone" android:onClick="launchHotSeat" /> <ImageView android:id="@+id/hotseat_right" style="@style/HotseatButton.Right" android:layout_toRightOf="@id/all_apps_button" android:src="@drawable/hotseat_browser" android:onClick="launchHotSeat" /> </RelativeLayout>



下面的两个ImageView控件就是左右的两个,一个电话,一个浏览器图标,在这里,你可以把这两个图标更换为其他功能,当然,具体功能实现得在Launcher.java代码中实现,如果想去掉这些图标,把上面那段代码删除,但是别忘了下面的Launcher.java中的代码。
hotseatLeft = (ImageView) findViewById(R.id.hotseat_left); hotseatLeft.setContentDescription(mHotseatLabels[0]); hotseatLeft.setImageDrawable(mHotseatIcons[0]); hotseatRight = (ImageView) findViewById(R.id.hotseat_right); hotseatRight.setContentDescription(mHotseatLabels[1]); hotseatRight.setImageDrawable(mHotseatIcons[1]);


屏蔽掉,当然还有他们的声明代码。
private ImageView hotseatLeft;
private ImageView hotseatRight;
有关他们的代码全部屏蔽以后,重新编译下,完成效果。

<think>我们正在处理用户的问题:用户想要调整Launcher3桌面图标拖动时底部框框的大小。具体来说,用户觉得这个框太大,想要调整它的大小。 在Android的Launcher3中,当用户长按并拖动一个应用图标时,会出现一个“删除”或“卸载”的区域(通常是一个垃圾桶图标)以及可能的工作区区域(即放置图标的网格区域)。用户提到的“底部框框”很可能是指拖动图标时出现在屏幕底部的目标区域(可能是垃圾桶区域或工作区提示区域)。 根据引用[3]中提到的思路,我们可以通过修改内边距(padding)或高度来调整目标区域的大小。但是,引用[3]是针对Workspace的图标垂直间距的调整,而用户的问题是关于拖动图标底部框框的大小调整。 在Launcher3中,拖动图标底部出现的区域通常由`DropTargetBar`(或类似名称)控制。我们需要找到控制这个区域的布局文件,并调整其大小。 步骤: 1. 首先,我们需要找到控制拖动目标栏(DropTargetBar)的布局文件。在Launcher3中,这个布局文件通常名为`drop_target_bar.xml`(或类似名称)。 2. 在这个布局文件中,我们可以设置整个目标栏的高度,以及其中每个目标(如删除、卸载等)的图标大小和布局参数。 3. 调整目标栏的高度:可以通过修改布局文件中的`android:layout_height`属性,或者通过修改内边距(padding)来调整。 具体操作: 假设我们找到了`drop_target_bar.xml`文件(位于`res/layout`目录下),我们可以这样调整: 原布局可能类似: ```xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" ...> <!-- 可能包含一个背景 --> <LinearLayout android:id="@+id/drag_button_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" ...> <!-- 这里包含删除、卸载等按钮 --> </LinearLayout> </FrameLayout> ``` 我们可以尝试修改整个`FrameLayout`的高度,或者修改内部`LinearLayout`的高度。但注意,如果高度设置为`wrap_content`,那么实际高度由内部按钮的高度决定。因此,我们可能需要调整按钮的大小。 然而,用户提到的是“底部框框”,可能是指整个目标栏的背景区域。我们可能需要调整背景图片的大小,或者调整布局的高度和内边距。 例如,我们可以将高度设置为一个固定值,比如: ```xml <FrameLayout ... android:layout_height="60dp" <!-- 原来可能是wrap_content,现在改为固定值 --> ...> ``` 或者,我们可以通过调整内边距来缩小内部按钮的显示区域,从而让整个目标栏看起来更小: ```xml <LinearLayout android:id="@+id/drag_button_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="8dp" <!-- 调整上下内边距 --> android:paddingBottom="8dp" ...> ``` 另外,如果目标栏的背景是一张图片,那么可能需要调整背景图片的尺寸或者缩放方式。 但是,请注意,在Launcher3的不同版本中,实现可能有所不同。因此,我们需要根据具体的Launcher3代码版本进行调整。 如果用户想要调整的是拖动图标时出现在底部的“工作区”提示区域(即显示页面指示和放置区域的框),那么可能需要修改`Workspace`相关的布局参数。在引用[3]中,用户通过修改Workspace的上下内边距来调整图标垂直间距,类似地,我们也可以调整工作区在拖动时显示的放置区域的大小。 具体来说,在Launcher3中,拖动图标时,工作区会显示一个矩形框(或者高亮区域)来表示可以放置的位置。这个区域的大小通常由单元格的大小决定,而单元格的大小在`CellLayout`中定义。我们可以尝试修改`CellLayout`的单元格大小,或者修改拖动时绘制的高亮区域的大小。 但是,由于用户特别提到“底部框框”,我们更倾向于认为是底部的目标栏(DropTargetBar)。因此,我们首先尝试调整`DropTargetBar`。 总结修改步骤: 1. 在Launcher3的布局文件中找到`drop_target_bar.xml`(或者类似名称)。 2. 调整整个布局的高度,或者调整内部元素的内边距、外边距等。 3. 如果目标栏包含按钮,可以调整按钮的大小(通过修改图标大小或按钮的布局大小)。 4. 如果调整后效果不明显,可能需要调整背景图片。 注意:修改后需要重新编译并运行Launcher3。 由于用户没有提供具体的Launcher3版本,以上建议基于常见的Launcher3实现。如果用户使用的是自定义的Launcher3,可能需要根据实际代码进行调整。 相关问题: 1. 如何修改Launcher3中拖动图标时出现的垃圾桶图标大小? 2. 在Launcher3中,如何调整工作区单元格的大小? 3. Launcher3中拖动操作的相关代码逻辑是怎样的?</think>### 调整Launcher3桌面图标拖动时底部框框大小的方法 在Launcher3中,拖动图标时出现的底部框框(通常称为"Drop Target Bar"或"Drag Layer")大小可通过以下步骤调整: #### 1. **修改布局文件高度** 找到控制底部区域的布局文件(通常为`drop_target_bar.xml`或`drag_layer.xml`),调整其高度值: ```xml <!-- 文件路径: res/layout/drop_target_bar.xml --> <FrameLayout android:id="@+id/drop_target_bar" android:layout_width="match_parent" android:layout_height="60dp" <!-- 修改此高度值(原值通常80-100dp)--> android:paddingTop="8dp" <!-- 可调整内边距进一步缩小 --> android:paddingBottom="8dp"> ... </FrameLayout> ``` #### 2. **调整图标容器大小** 底部框内的图标容器大小会影响整体高度,修改`drop_target_bar.xml`中的图标布局参数: ```xml <LinearLayout android:id="@+id/button_bar" android:layout_height="40dp" <!-- 减小容器高度 --> android:gravity="center"> <!-- 垃圾桶/应用信息等图标 --> </LinearLayout> ``` #### 3. **修改代码逻辑(可选)** 在`DragLayer.java`中调整布局测量逻辑: ```java // 文件路径: src/com/android/launcher3/dragndrop/DragLayer.java @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); // 找到底部区域并重置高度 View dropBar = findViewById(R.id.drop_target_bar); if (dropBar != null) { dropBar.getLayoutParams().height = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 60, getResources().getDisplayMetrics()); // 设置新高度 } } ``` #### 4. **调整边距(推荐辅助方案)** 通过减小上下边距间接缩小框体: ```xml <!-- 在drop_target_bar.xml中添加 --> <FrameLayout ... android:layout_marginTop="-10dp" <!-- 负边距减小顶部空间 --> android:layout_marginBottom="-10dp"> <!-- 负边距减小底部空间 --> ``` > **注意事项** > - 不同Launcher3版本文件路径可能略有差异(AOSP版本通常在`src/com/android/launcher3`)[^3] > - 修改后需清理构建(`./gradlew clean`)避免缓存问题 > - 建议使用`dp`单位保持设备兼容性
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值