我想知道如何在 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;