Gmail导航抽屉效果

时间:2013-08-07 18:20:58

标签: java android

我想知道如何在Gmail应用中执行淡入淡出效果。当您在导航抽屉上拖动手指并打开或关闭它时,导航抽屉下方的视图会变得更亮或更暗(如果将其移动到左侧,它将变得更亮,反之亦然)。

我尝试像下面的代码那样做,但它崩溃了,而且它在视觉上不如Gmail应用程序。

    String colorString = "0x00000000";

    int max = MAX_SIZE_X;
    int auxMax = (int) (MAX_SIZE_X * 0.9); // 90
    int betMax = (int) (MAX_SIZE_X * 0.8); // 80
    int auxMaM = (int) (MAX_SIZE_X * 0.7); // 70
    int betMaM = (int) (MAX_SIZE_X * 0.6); // 60
    int auxMid = (int) (MAX_SIZE_X * 0.5); // 50
    int betMid = (int) (MAX_SIZE_X * 0.4); // 40
    int auxMiM = (int) (MAX_SIZE_X * 0.3); // 30
    int betMiM = (int) (MAX_SIZE_X * 0.2); // 20
    int betMin = (int) (MAX_SIZE_X * 0.1); // 10

    if (touch < max && touch >= auxMax) {
        colorString = "#88000000";

    } 
    if (touch < auxMax && touch >= betMax) {
        colorString = "#84000000";

    } 
    if (touch < betMax && touch >= auxMaM) {
        colorString = "#80000000";

    } 
    if (touch < auxMaM && touch >= betMaM) {
        colorString = "#76000000";

    } 
    if (touch < betMaM && touch >= auxMid) {
        colorString = "#72000000";

    } 
    if (touch < auxMid && touch >= betMid) {
        colorString = "#68000000";

    } 
    if (touch < betMid && touch >= auxMiM) {
        colorString = "#64000000";

    } 
    if (touch < auxMiM && touch >= betMiM) {
        colorString = "#60000000";

    } 
    if (touch < betMiM && touch >= betMin) {
        colorString = "#00000000";

    }
    colorInt = Color.parseColor(colorString);

    return colorInt;

2 个答案:

答案 0 :(得分:2)

请从Google开发者网站查看以下示例。它可能会有所帮助。

http://developer.android.com/training/implementing-navigation/nav-drawer.html

可以找到有关导航抽屉模式的详细信息:

http://developer.android.com/design/patterns/navigation-drawer.html

答案 1 :(得分:0)