您的位置:首页 > 移动开发 > Android开发

android4.2 Launcher2界面两边的渐变的去除方法

2013-11-01 20:17 330 查看
android4.2 Launcher2主界面效果如下图:



如图所示,左右两边有黑色的渐变,看起来感觉怪怪的。现提供一种去掉它的方法。

步骤1
打开文件launcher.xml,将下述代码片段中的android:background属性去掉。

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"

android:id="@+id/launcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/workspace_bg">

<com.android.launcher2.DragLayer
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"

android:id="@+id/drag_layer"
android:background="@drawable/workspace_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

调整后的情况如下:

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"

android:id="@+id/launcher"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.android.launcher2.DragLayer
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"

android:id="@+id/drag_layer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

步骤2
打开文件Launcher2.java,不难看出,代码中有

private Drawable mWorkspaceBackgroundDrawable;
private Drawable mBlackBackgroundDrawable;

两个属性,用于绘制wordkspace背景。继续往下跟踪代码,可找到下面的代码片段

mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
mBlackBackgroundDrawable = new ColorDrawable(Color.BLACK);

......
......

private void setWorkspaceBackground(boolean workspace) {
mLauncherView.setBackground(workspace ?
mWorkspaceBackgroundDrawable : mBlackBackgroundDrawable);
}

方法setWorkspaceBackground大意是根据布尔量wordspace的值情况选用不同的属性绘制背景,这里,我们选择将此方法的内容注释掉。变成

private void setWorkspaceBackground(boolean workspace) {
//mLauncherView.setBackground(workspace ?
// mWorkspaceBackgroundDrawable : mBlackBackgroundDrawable);
}

步骤3
重新构建Launcher2.apk,push进机器验证,得到下图所示效果。完成此需求,方法有多种,大家可以深入了解代码实现,取最佳最优的处理方法。



评论这张

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: