android4.2.2 启动器界面两边的渐变的去除方法

android4.2 Launcher2主界面效果如下图:
android4.2 Launcher2界面两边的渐变的去除方法 - ka布 - I/O
如图所示,左右两边有黑色的渐变,看起来感觉怪怪的。现提供一种去掉它的方法。

步骤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进机器验证,得到下图所示效果。完成此需求,方法有多种,大家可以深入了解代码实现,取最佳最优的处理方法。
android4.2 Launcher2界面两边的渐变的去除方法 - ka布 - I/O
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章