I have a view, let's call it "A", inside of a scrollview. I want to be able to draw on "A" and then scroll horizontally through the drawing. To do this, I've been expanding the width programatically:
val chart = findViewById<ConstraintLayout>(R.id.chart)
chart.layoutParams.width = someWidth
chart.requestLayout()
This works, except it expands the to the RIGHT. I need to be able to expand the width from both sides, so it appears as if it's zooming into one area.
If I set the layout_gravity to "center" and set the width to some large value in my xml, it shows that the view is expanded in both directions in the designer, but in practice it expands from the right.
I've tried editing the margins:
val params = (chart.layoutParams as MarginLayoutParams)
params.setMargins(-someWidth/2), 0, -someWidth/2, 0)
glucoseChart.requestLayout()
But for some reason, this doesn't seem to actually expand the width, and the scrollview is un-scrollable.
Any ideas?