-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainActivity.java
39 lines (34 loc) · 1.33 KB
/
MainActivity.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
package com.itheima.demo2;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private FlowLayout flowLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
flowLayout = new FlowLayout(getBaseContext());
setContentView(flowLayout);
int padding = 10;
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < 300; i= i+20) {
list.add(i + "-:-" + i);
}
flowLayout.setPadding(padding, padding, padding, padding);
TextView tv;
for (String text : list) {
tv = new TextView(getBaseContext());
Drawable pressed = DrawableUtil.generateDrawable(ColorUtil.randomColor(), 5);
Drawable normal = DrawableUtil.generateDrawable(ColorUtil.randomColor(), 5);
tv.setBackground(DrawableUtil.generateSelector(pressed, normal));
tv.setTextColor(Color.WHITE);
tv.setPadding(padding, padding, padding, padding);
tv.setText(text);
tv.setClickable(true);
flowLayout.addView(tv);
}
}
}