Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How to create a View Programmatically

I need to create a view programmatically. The controls(buttons, labels, etc.) and their positions are known only at runtime.

Here I found "Defining a Layout Programmatically": http://mobile.tutsplus.com/tutorials/android/android-layout/

but I need to be able to draw components at exact locations so LinearLayout, TableLayout etc. doesn't work for me.

How can I do this?

like image 910
Caner Avatar asked Aug 01 '11 08:08

Caner


1 Answers

Create a custom ViewGroup; this allows you to manage placements of each of the children you have (buttons, labels, etc) manually. Check this vid from the google IO event in 2009 titled 'Make your Android UI Fast and Efficient', specifically from about 43 minutes onward for more details.

like image 81
MrJre Avatar answered Sep 22 '22 06:09

MrJre