https://kotlinlang.org logo
Title
j

jeff

12/21/2020, 11:02 PM
Can
Container
be given an anchor? Or is there an alternative that can? I have two views that I want to scale up and down together. I put them in a container thinking I could just change the container's `scale`but doing so makes them move as they scale, since they're using the parent container's "anchor" which is just the grandparent's origin. Thoughts? (apologies for all the questions, and thanks to everyone who's been responding!)
m

Mayank

12/22/2020, 5:49 PM
Container does not support anchor. You can try QView which can apply properties like scale to multiple views at once. I tried scaling with this example. Let me know if it solves your usecase or not
container {
            val rect = solidRect(100, 100, Colors.RED) {
                position(150, 150)
                center()
            }
            val circle = circle(64.0, Colors.BLUE) {
                position(250, 250)
                center()
            }
            val qView = QView(listOf(rect, circle))
            launchAnimate(looped = true, time = 2.seconds) {
                tween(qView::scale[2.0], time = time)
                tween(qView::scale[1.0], time = time)
            }
        }

        val radius = 4.0
        val rectCenter = circle(radius, Colors.GREEN).position(150.0 - radius, 150.0 - radius)
        val circleCenter = circle(radius, Colors.GREEN).position(250.0 - radius, 250.0 - radius)
j

jeff

12/22/2020, 9:49 PM
Thanks! This helped me figure out that my problem was something dumb I was doing, not a limitation of
Container
. But it also intrigued me about QView, which I don't see in the documentation anywhere. Looking at the impl it seems to be just a list of views that you can manipulate together? Cool!
m

Mayank

12/23/2020, 11:55 AM
Glad it helped