-
Notifications
You must be signed in to change notification settings - Fork 37
enhancement: access to layoutparams after lp tweak #34
Comments
setting layout margins is definitely a pain point currently I have to run: where margins is something ugly like and it requires having set lp beforehand |
Yeah, I actually avoid using margins, replacing them with padding where possible :) From your suggestions, I think |
After some experiments with macroid, I too feel lp as a pain point (if not using xml layouts 😛). |
@dant3 I think we can agree that Android’s |
By the way, how much is it desired to change layout params after layout? If they are only set once, maybe widgets could be wrapped into something like this before being added to the layout: // isParams is generated by an implicit macro
case class LP[L <: ViewGroup, +W <: View, X](view: W, params: X)(implicit isParams: IsParams[X, L]) I guess this could offer more type safety if done right, but not sure about the details yet. |
I don't understand how this would streamline the lp generation? isParams only links VG and VG.LP? Sent from my phone
|
Oh, I suppose the case class can take a function to operate on the params. Rather than params: X it should be params: (X => Unit)? |
Also, interestingly, it'd be nice if WindowManager.LayoutParams could be supported as well. It isn't a view group... But one applies the layout params to content views.. |
Sorry for not being elaborate enough. To give an example, if we wanted to add a LP[LinearLayout, Button, LinearLayout.LayoutParams](w[Button], new LinearLayout.LayoutParams(...)) although your idea with implicitly[IsParams[LinearLayout.LayoutParams, LinearLayout]]
implicitly[IsParams[ViewGroup.LayoutParams, LinearLayout]]
... Does this make sense? To deal with |
Oh well, this is somewhat orthogonal, but I thought extra type safety might help to deal with this horrible API. As far as configuring the actual params is concerned, |
This is basically what I came up with for my own thing.
|
Oh, can't forget the rest.
|
many layout params require field changes instead of only constructor parameters (e.g. gravity, span, relative layout stuff, etc. [yes, there's RuleRelativeLayout, but that's besides the point]).
I don't have a good solution for this yet, but maybe something like an optional parameter set, e.g.
lp[A](...)(Map(field -> value))
or
lp[A](...) { p: A.LayoutParams(????) => p.... }
// I don't see how this is possibleAlternatively, figure out a good way of creating AttributeSets so that one can do
lp[A](Map(...).toAttributeSet)
etc.
The text was updated successfully, but these errors were encountered: