-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainActivity.cs
79 lines (66 loc) · 2.35 KB
/
MainActivity.cs
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
using System;
using Android.App;
using Android.Widget;
using Android.OS;
using EasyLayout.Droid.Sample.Views;
namespace EasyLayout.Droid.Sample
{
[Activity(Label = "EasyLayout.Droid.Sample", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private RelativeLayout _relativeLayout;
private Button _layoutExampleButton;
private Button _listExampleButton;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
AddViews();
ConstrainLayout();
SetContentView(_relativeLayout);
}
protected override void OnStart()
{
base.OnStart();
SubscribeEvents();
}
protected override void OnStop()
{
base.OnStop();
UnsubscribeEvents();
}
private void SubscribeEvents()
{
_layoutExampleButton.Click += LayoutExampleButtonOnClick;
_listExampleButton.Click += ListExampleButtonOnClick;
}
private void UnsubscribeEvents()
{
_layoutExampleButton.Click -= LayoutExampleButtonOnClick;
}
private void ListExampleButtonOnClick(object sender, EventArgs e)
{
StartActivity(typeof(ViewProductsActivity));
}
private void LayoutExampleButtonOnClick(object sender, EventArgs eventArgs)
{
StartActivity(typeof(LayoutExampleActivity));
}
private void AddViews()
{
_relativeLayout = ViewUtils.AddRelativeLayout(this);
_layoutExampleButton = _relativeLayout.AddButton("Layout Examples");
_listExampleButton = _relativeLayout.AddButton("List Example");
}
private void ConstrainLayout()
{
_relativeLayout.ConstrainLayout(() =>
_layoutExampleButton.Top == _relativeLayout.Top + 20
&& _layoutExampleButton.Left == _relativeLayout.Left + 20
&& _layoutExampleButton.Right == _relativeLayout.Right - 20
&& _listExampleButton.Top == _layoutExampleButton.Bottom + 20
&& _listExampleButton.Left == _layoutExampleButton.Left
&& _listExampleButton.Right == _layoutExampleButton.Right
);
}
}
}