开发者

Want to change LinearLayout layout at runtime

开发者 https://www.devze.com 2023-01-13 15:33 出处:网络
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

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 wit开发者_运维百科h 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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消