博文地址
目录
不透明度转换
不透明度转换简表
- 透明度
100%
指的是完全透明,这时候的颜色没有意义,对应十六进制 00
- 不透明度
100%
指的是完全不透明,这是颜色的默认值,对应十六进制 FF
- Android 中 View 的
alpha
属性指的是不透明度,默认值为 1.0f
或 255
- 平常设计同学说的、设计稿中给的、标注中的
opacity
都是指的不透明度
0% |
1% |
2% |
3% |
4% |
5% |
6% |
7% |
8% |
9% |
00 |
03 |
05 |
08 |
0A |
0D |
0F |
12 |
14 |
17 |
10% |
11% |
12% |
13% |
14% |
15% |
16% |
17% |
18% |
19% |
1A |
1C |
1F |
21 |
24 |
26 |
29 |
2B |
2E |
30 |
20% |
21% |
22% |
23% |
24% |
25% |
26% |
27% |
28% |
29% |
33 |
36 |
38 |
3B |
3D |
40 |
42 |
45 |
47 |
4A |
30% |
31% |
32% |
33% |
34% |
35% |
36% |
37% |
38% |
39% |
4D |
4F |
52 |
54 |
57 |
59 |
5C |
5E |
61 |
63 |
40% |
41% |
42% |
43% |
44% |
45% |
46% |
47% |
48% |
49% |
66 |
69 |
6B |
6E |
70 |
73 |
75 |
78 |
7A |
7D |
50% |
51% |
52% |
53% |
54% |
55% |
56% |
57% |
58% |
59% |
80 |
82 |
85 |
87 |
8A |
8C |
8F |
91 |
94 |
96 |
60% |
61% |
62% |
63% |
64% |
65% |
66% |
67% |
68% |
69% |
99 |
9C |
9E |
A1 |
A3 |
A6 |
A8 |
AB |
AD |
B0 |
70% |
71% |
72% |
73% |
74% |
75% |
76% |
77% |
78% |
79% |
B3 |
B5 |
B8 |
BA |
BD |
BF |
C2 |
C4 |
C7 |
C9 |
80% |
81% |
82% |
83% |
84% |
85% |
86% |
87% |
88% |
89% |
CC |
CF |
D1 |
D4 |
D6 |
D9 |
DB |
DE |
E0 |
E3 |
90% |
91% |
92% |
93% |
94% |
95% |
96% |
97% |
98% |
99% |
E6 |
E8 |
EB |
ED |
F0 |
F2 |
F5 |
F7 |
FA |
FC |
不透明度转换代码
核心代码
private static String getHexString(int i) {
float temp = 255 * i * 1.0f / 100f;
int round = Math.round(temp); //四舍五入
String hexString = Integer.toHexString(round);
if (hexString.length() < 2) {
hexString = "0" + hexString;
}
return hexString.toUpperCase();
}
输出列表格式
private static void listFormat() {
System.out.println("-------不透明度百分比对应的十六进制转换表-------");
for (int i = 0; i <= 100; i++) {
System.out.println("百分比:" + i + "%" + "\t十六进制:" + getHexString(i));
}
}
输出markdown格式
private static void markdownFormat() {
System.out.println("-------不透明度百分比对应的十六进制转换表-------");
for (int i = 0; i <= 9; i++) {
StringBuilder transparency = new StringBuilder();
StringBuilder percent = new StringBuilder();
int value = 10 * i;
for (int j = 0; j <= 9; j++) {
transparency.append("|").append(" ").append(getHexString(value)).append(" ");
percent.append("|").append(" ").append(value++).append("%").append(" ");
}
percent.append("|\n| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |");
percent.append("\n").append(transparency).append("|\n");
System.out.println(percent.toString());
}
}
2019-6-30