Width change of a view is not reflected in UI even though view.isInLayout is true

Viewed 9

I'm changing the width of a view and using view.isInLayout to decide whether to call requestLayout() or not.

But in some cases, even if view.isInLayout returns true in the function which updates the width, the width is not updated in UI.

Calling requestLayout() after updating the width, irrespective of layout's state makes the UI update as expected

However, requestLayout's official doc states, This (requestLayout) should not be called while the view hierarchy is currently in a layout pass.

1 Answers

Width and height of any view can be change by changing its layout params

 val layoutParams = LayoutParams(WIDTH, LayoutParams.WRAP_CONTENT)
 view.layoutParams = layoutParams

here view is your view(imageview/textview/LinearLayout etc)

Related