Reputation: 1400
I'm trying to build buttons via xml layout, depending on parameters grabbed from the server (x/y coords mostly). Best I got so far requires me to update the app each time I want a new layout, but I'm trying to find a more efficient way. So the number of actual buttons and their position is relative to the data grabbed from the database. How would I go on about doing this?
Upvotes: 0
Views: 52
Reputation: 16832
To move buttons at run-time, use an empty <View />
whose size is set programmatically; the buttons will be, say, below it. (Works both for <LinearLayout ...>
and <RelativeLayout ...>
). Use ViewTreeObserver.OnGlobalLayoutListener
and getMeasuredWidth() to get the actual sizes.
Note that you can do really a lot by just making some buttons/views invisible (someView.setVisibility(View.GONE)
, the other two possible values are View.VISIBLE
and View.INVISIBLE
). If possible, you should prefer this approach because it allows you to have a more or less sane layout under any circumstances.
Upvotes: 1