/
DiffHeightTextActivity.java
110 lines (102 loc) · 3.25 KB
/
DiffHeightTextActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.single.flowlayout;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.library.flowlayout.FlowAdapter;
import com.library.flowlayout.FlowLayout;
import java.util.Arrays;
import java.util.Random;
public class DiffHeightTextActivity extends AppCompatActivity {
private static final String arrays[] = new String[]{"1.C",
"2.Java",
"3.Objective-C",
"4.C++",
"5.PHP",
"6.C#",
"7.(Visual) Basic",
"8.Python",
"9.Perl",
"10.JavaScript",
"11.Ruby",
"12.Visual Basic .NET",
"13.Transact-SQL",
"14.Lisp",
"15.Pascal",
"16.Bash",
"17.PL/SQL",
"18.Delphi/Object Pascal",
"19.Ada",
"20.MATLAB", "1.C",
"2.Java",
"3.Objective-C",
"4.C++",
"5.PHP",
"6.C#",
"7.(Visual) Basic",
"8.Python",
"9.Perl",
"10.JavaScript",
"11.Ruby",
"12.Visual Basic .NET",
"13.Transact-SQL",
"14.Lisp",
"15.Pascal",
"16.Bash",
"17.PL/SQL",
"18.Delphi/Object Pascal",
"19.Ada",
"20.MATLAB",
"1.C",
"2.Java",
"3.Objective-C",
"4.C++",
"5.PHP",
"6.C#",
"7.(Visual) Basic",
"8.Python",
"9.Perl",
"10.JavaScript",
"11.Ruby",
"12.Visual Basic .NET",
"13.Transact-SQL",
"14.Lisp",
"15.Pascal",
"16.Bash",
"17.PL/SQL",
"18.Delphi/Object Pascal",
"19.Ada",
"20.MATLAB", "20.MATLAB"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FlowLayout re = (FlowLayout) findViewById(R.id.flow);
// FlowLayout flowLayout = new FlowLayout(this);
re.setAdapter(new FlowAdapter<String>(this, Arrays.asList(arrays)) {
@Override
protected int generateLayout(int position) {
if (position % 3 == 0) {
return R.layout.flow_item_heigher;
} else {
return R.layout.flow_item;
}
}
@Override
protected void getView(String o, View parent) {
TextView text = (TextView) parent.findViewById(R.id.flow_text);
text.setText(o);
text.setBackgroundDrawable(getBack());
}
private Drawable getBack() {
GradientDrawable drawable = new GradientDrawable();
drawable.setCornerRadius(8);
drawable.setColor(Color.rgb(new Random().nextInt(255), new Random().nextInt(255), new Random().nextInt(255)));
return drawable;
}
});
}
}