6

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?

Cœur
39k25 gold badges207 silver badges282 bronze badges
asked Aug 1, 2011 at 8:45
1
  • 2
    actually linearlayout's will work fine ... you just have to transform your locations to margins and paddings using linearlayouts Commented Aug 1, 2011 at 8:48

2 Answers 2

4

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.

answered Aug 1, 2011 at 8:58
Sign up to request clarification or add additional context in comments.

Comments

0

I would take a look at the Lunar lander example in the android API samples here http://developer.android.com/resources/samples/LunarLander/index.html. This helped me out tremendously when starting out making games and having to dynamically draw to the screen.

answered Aug 1, 2011 at 8:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.