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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章