Search…
Scroll Container

Overview

The Container scroll is a container that has side scroll, horizontal scroll or no scroll.

How to use

1
public class ScrollContainerSample extends MainWindow {
2
3
public ScrollContainerSample(){
4
setUIStyle(Settings.Material);
5
}
6
7
@Override
8
public void initUI() {
9
super.initUI();
10
ScrollContainer sc = new ScrollContainer(false, true);
11
int gap = UnitsConverter.toPixels(DP + 16);
12
sc.setInsets(gap, gap, gap, gap);
13
add(sc, LEFT, TOP, FILL, FILL);
14
15
Button b;
16
ScrollContainer sc1, sc2, sc3;
17
// a ScrollContainer with both ScrollBars
18
sc.add(new Label("Vertical and horizontal:"), LEFT, TOP);
19
sc.add(sc1 = new ScrollContainer());
20
sc1.setBorderStyle(BORDER_ROUNDED);
21
sc1.setInsets(3, 3, 3, 3);
22
sc1.setRect(LEFT, AFTER, FILL, SCREENSIZE + 30);
23
int xx = new Label("Name99").getPreferredWidth() + 2; // edit's alignment
24
for (int i = 0; i < 50; i++) {
25
sc1.add(new Label("Name" + i), LEFT, AFTER + 10);
26
sc1.add(new Edit(), xx, SAME, SCREENSIZE + 90, PREFERRED);
27
if (i % 3 == 0) {
28
sc1.add(new Button("Go"), AFTER + 2, SAME, PREFERRED, SAME);
29
}
30
}
31
32
// a ScrollContainer with vertical ScrollBar disabled
33
sc.add(new Label("Horizontal-only:"), LEFT, AFTER + gap);
34
sc.add(sc2 = new ScrollContainer(true, false));
35
sc2.setBorderStyle(BORDER_ROUNDED);
36
sc2.setInsets(3, 3, 3, 3);
37
int lines = Settings.screenHeight > 320 ? 4 : 3;
38
sc2.setRect(LEFT, AFTER, FILL, lines * (fmH + Edit.prefH) + fmH / 2);
39
for (int i = 0; i < lines; i++) {
40
sc2.add(new Label("Name" + i), LEFT, AFTER);
41
sc2.add(new Edit(""), xx, SAME, PARENTSIZE + 200, PREFERRED); // fit
42
sc2.add(new Button("Go"), AFTER, SAME, PREFERRED, SAME);
43
}
44
45
// a ScrollContainer with horizontal ScrollBar disabled
46
sc.add(new Label("Vertical-only:"), LEFT, AFTER + gap);
47
sc.add(sc3 = new ScrollContainer(false, true));
48
sc3.setBorderStyle(BORDER_ROUNDED);
49
sc3.setInsets(3, 3, 3, 3);
50
sc3.setRect(LEFT, AFTER, FILL, SCREENSIZE + 30);
51
for (int i = 0; i < 50; i++) {
52
sc3.add(new Label("Name" + i), LEFT, AFTER);
53
sc3.add(b = new Button("Go"), RIGHT, SAME, PREFERRED, SAME);
54
sc3.add(new Edit(""), xx, SAME, FIT - 2, PREFERRED, b); // fit
55
}
56
}
57
}
Copied!

References