[Lazarus] Android Target GUI
Sven Barth
pascaldragon at googlemail.com
Fri Feb 17 10:27:13 CET 2012
Am 17.02.2012 10:23, schrieb Felipe Monteiro de Carvalho:
> On Fri, Feb 17, 2012 at 9:11 AM,<michael.vancanneyt at wisa.be> wrote:
>> Android uses XML files to specify the layout. This is the recommended way by
>> Google. You can build the GUI in code as well, but then you're pretty much
>> in uncharted territory.
>
> It is pretty trivial to build the UI without XML. I never used the XML
> part while programming for Android. For example (in pseudo-code):
>
> procedure TMyActivity.OnCreate;
> var
> layout: TAbsoluteLayout;
> params: TAbsoluteLayout_LayoutParams;
> tv: TTextView;
> et: TTextView;
> btn: TButton;
> ClickCount: Integer = 0;
> begin
> // Prepares the UI of the program
> layout := TAbsoluteLayout.Create;
>
> tv := TTextView.Create;
> tv.setText('The first Pascal Android application =)');
> params := TAbsoluteLayout_LayoutParams.Create(320, 300, 0, 120);
> layout.addView(tv, params);
> params.Free;
>
> et := TEditText.Create;
> et.setText('edit me please');
> params := TAbsoluteLayout_LayoutParams.Create(320, 50, 0, 0);
> layout.addView(et, params);
> params.Free;
>
> btn := TButton.Create;
> btn.setText('Go!');
> btn.setOnClickListener(@buttonClickCallback);
> params := TAbsoluteLayout_LayoutParams.Create(320, 50, 0, 60);
> layout.addView(btn, params);
> params.Free;
>
> Activity.setContentView(layout);
> end;
>
This part is rather easy, but it gets more interesting when using menus
or the views for items in list views.
Also the XML layouts allows for a more clean seperation of layout and
code ;)
Regards,
Sven
More information about the Lazarus
mailing list