0

First time poster, new to Android, and I seem to have hit a roadblock on this problem:

I'm creating a dynamic layout, consisting of several identical "composite" objects (these are basically "floating" LinearLayouts, each containing an icon (ImageView) and a caption (TextView)). The (x,y) coordinates of each LinearLayout are subject to change, based on user actions, and require precise placement (ie: can't use RelativeLayout, etc), so I'm positioning them inside an AbsoluteLayout.

During onCreate(), I'm adding each of these objects as a child View inside an AbsoluteLayout object, then setting the (x,y) manually. No problems so far, works great, initial layout is perfect.

The problem:

After the initial onCreate(), I can't get the (x,y) positions of these objects to change on the screen. I can update their layoutParams, but the on-screen layout (inside the AbsoluteLayout) is never refreshed. I've tried forceLayout(), invalidate(), requestLayout(), none of them work.

Is there a problem with my basic approach here, or is there something I'm just missing?

I'm thinking of changing to a SurfaceView and just doing the rendering the hard way, but my code works 99% great right now and I don't want to change it if I don't have to. The only problem is that the layout manager simply refuses to register the position changes for my child objects.

Help, what am I doing wrong?

dreambig
  • 271
  • 3
  • 4

1 Answers1

0

Did you try creating a handler for UI and then updating your UI from that..

UI will not be able update from different thread. So, create a thread handler for UI and update the changes to UI using that handler.

-vinay

Vinay
  • 2,395
  • 3
  • 30
  • 35
  • I'm confused here, as I thought the UI lived in the main thread (same one that called onCreate()). Is that not the case? I haven't created any additional threads in my application yet. – dreambig Aug 04 '10 at 09:58
  • You are right, UI is part of the main thread. It will be running until the app is killed. But when you try to update the UI from a different place, you might not have access. Usually, what I have noticed is that it fails when I wait for some Events. – Vinay Aug 05 '10 at 12:55
  • 1
    Update: I moved everything into a custom SurfaceView object, and it's working MUCH better. The following tutorial was a great starting place for me: http://www.droidnova.com/playing-with-graphics-in-android-part-i,147.html – dreambig Aug 17 '10 at 02:09