Layout (in HorizontalScrollView) not getting updated on 2nd consecutive layout() with different para


I have a RelativeLayout (a direct child of a HorizontalScrollView), which stretches beyond the screen bounds, in which I've placed some views dynamically.

In order to capture a part of the view (as a bitmap), I do the following:

v.layout(0, 0, cw, ch); v.draw(canvas)

And then in order to restore the original bounds (which is the full width of the HSV), call layout() again, but can also scroll till the <em>bounds 0->cw</em> instead of fullWidth.

v.layout(0, 0, fullWidth, fullHeight); v.invalidate();

I've already tried all the following approaches and as a desperate measure all their combinations:

v.getParent().invalidateChild(v, new Rect(0, 0, width, height)); ((Activity)v.getContext()).getWindow().getDecorView().findViewById(android.R.id.content).invalidate(); v.forceLayout();

But the layout doesn't update, until I focus on another view (clicking another button/view).


use simple a v.requestLayout();

From the <a href="http://developer.android.com/reference/android/view/View.html#requestLayout()" rel="nofollow">docs</a>:


To initiate a layout, call <a href="http://developer.android.com/reference/android/view/View.html#requestLayout()" rel="nofollow">requestLayout()</a>. This method is typically called by a view on itself when it believes that is can no longer fit within its current bounds.


Further great reading: <a href="http://developer.android.com/guide/topics/ui/how-android-draws.html" rel="nofollow">How Android Draws Views</a>


  • ERROR about identify different colors
  • checking the Colors Opencv Python
  • How to store Hex string in an Integer variable in android???
  • ContextCompat.getcolor() going to null object reference
  • Can I make a variable temporarily volatile?
  • Restoring deleted mysql database
  • Spring MVC AccessDeniedException 500 error received instead of custom 401 error for @PreAuthorized u
  • “Member has private access error” after deleting plugin in CakePHP using PhpStorm
  • How to find documents with exactly the same array entries as in a query
  • Get pretty git rev name
  • How to distribute Java-based software?
  • WPF Image control clipping
  • Android - HorizontalScrollView will not scroll all the way
  • Visual studio alerts workspace already exists
  • Monotouch crashes with NullReferenceException on non nullable object
  • How to draw a line dynamically in android [duplicate]
  • Open Existing DB in MySQL WorkBench
  • C#: Import/Export Settings into/from a File
  • Who propagate bugfixes across branches (corporate development)?
  • xcode don't localize specific strings
  • Moving Android View and preventing onDraw to be called over and over again
  • Chart.js Multiple dataset
  • Blackberry - Custom EditField Cursor
  • print() is showing quotation marks in results
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Android fill_parent issue
  • ilmerge with a PFX file
  • Update CALayer sublayers immediately
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Get object from AWS S3 as a stream
  • How to show dropdown in excel using jrxml (jasper api)?
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Change div Background jquery
  • How does Linux kernel interrupt the application?
  • python draw pie shapes with colour filled
  • Busy indicator not showing up in wpf window [duplicate]
  • Running Map reduces the dimensions of the matrices
  • Android Heatmap on canvas or ImageView
  • Why do underscore prefixed variables exist?