0

Whenever a new view is added or removed, everything is adjusted. I can see how in majority of use-cases this is a very good thing, but unfortunately for me, it's something I need to avoid. I'm assuming that onMeasure() is called whenever a view is removed or added, resulting in it changing the X and Y coordinates I gave it, however I want to "disable" this.

My app utilizes dynamically moving and resizing views, determined by the user at runtime, hence if whenever the user removes a view or adds a new one, it shifts everything around, it'd be extremely annoying. Also I'd think that (although not sure) that preventing this could only help performance right? Not measuring each view, in fact, I do not want it to measure it at all because, once again, the user decides the view size and location, not the linear layout.

I was thinking of creating my own ViewGroup, but I've never done this before. I know you can extend a pre-existing one, like LinearLayout or RelativeLayout, but I need help determining which one I should use, and whether or not I should just create a full on ViewGroup.

As I said, it doesn't need to measure the views at all, and in fact, if it were possible, a container that does nothing would be optimal, and I'd think would yield more performance. Can anyone help me with this problem?

Summary:

Need a way to either prevent a pre-existing ViewGroup, I.E FrameLayout, RelativeLayout and LinearLayout, that do not adjust the position nor size of the view, or create a new ViewGroup which doesn't do any measuring at all because the user defines the location and size at runtime and should not be altered by the container.

If this is a bad question or another question exists that answers this, please let me know.

Louis Jenkins
  • 391
  • 1
  • 2
  • 10
  • if you dont want custom `ViewGroup` use `FrameLayout` then – pskink Nov 28 '15 at 21:04
  • I've a feeling that a custom ViewGroup would be best in the long term, however I'd need a nice example of this. Majority of people extend an existing layout, like LinearLayout or RelativeLayout, but I don't know enough about how ViewGroups work fundamentally to efficiently create my own ViewGroup. Also with FrameLayout, I'm unsure as to how to "move" each view. Do you move everything by updating each margin? how would I effectively ensure that each view doesn't go out of bounds? If I update margins does it actually update it's X and Y coordinates? – Louis Jenkins Nov 28 '15 at 21:12
  • you dont even have to use layout params: you can use translationX / translationY properties, and no, you have to contol them as views may go "out of bounds" – pskink Nov 28 '15 at 21:17
  • I got confused for a bit. I meant resizing. I can use setX and setY, or as you put it, translationX/Y, but for resizing the view I must set layout parameters. – Louis Jenkins Nov 28 '15 at 21:18
  • for size yes, for position no, any existing translate animators use translationX/Y properties – pskink Nov 28 '15 at 21:19
  • So how would I go about dynamically resizing the views in a FrameLayout? Also can I confirm that a FrameLayout does not touch it's children after another child has been added/removed? – Louis Jenkins Nov 28 '15 at 21:20
  • ok if you want to size them you have to use params, but more likely you move them than size, don't you? frame layout does not touch child views, trust me – pskink Nov 28 '15 at 21:22
  • Regardless of how often I move more often than resize, it needs to be able to resize the view. Can I use View.setLayoutParams with a FrameLayout.LayoutParams somehow? I tried before but it said it needed a MarginLayoutParams instead – Louis Jenkins Nov 28 '15 at 21:26
  • 1
    yes, you have to use `FrameLayout.LayoutParams` – pskink Nov 28 '15 at 21:30
  • !!! That's strange, I swear I did it earlier, but I tried it again and it somehow worked. My bad, thanks for the reply. – Louis Jenkins Nov 28 '15 at 21:34

0 Answers0