views:

36

answers:

1

I've been searching, but can't find a way to do this. I want the ability to re-arrange Views in a LinearLayout, without specifying specific pixel locations, at runtime. for my proof of concept, I have a layout with 2 TextViews, one red, and one black. The red TextView is on the left. I want onClick to set it to be on the right, without adjusting margins, as if I'd re-written the XML of the layout, with the red TextView second. Is there a way to do this? I can't seem to find it.

A: 

I may be wrong but what about this: TextView and many others have a setLayoutParams function, and can take in a LayoutParams object.

Take a look at layout params http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#LinearLayout.LayoutParams%28android.content.Context,%20android.util.AttributeSet%29

One of the constructors for LayoutParams can take in the context and AttributeSet. Going further, Attribute set is here http://developer.android.com/reference/android/util/AttributeSet.html

If you look at the sample code they parse an xml file to get the attributeset. perhaps you could do the same?

Realn0whereman
Thanks for the post. I may end up using this XML set as a method to accomplish my end goal. I was able to get my proof of concept to work by binding the 2 TextViews to vairables, then doing removeAllViews() on my linear layout, then doing addView(View v) on the black text, then the red text. I'm trying to get (very) simple drag, where each drag action commits a database change, and refreshes the screen from the database.
Tyler
Check out this guy:http://www.mail-archive.com/[email protected]/msg44637.htmlHe wrote his own view. You could create something likepublic class MovingTextView extends TextView{}and create some moving methods.
Realn0whereman