Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: RoundRectShape: Modify corner radii
    primarykey
    data
    text
    <p>I have a <code>RoundRectShape</code> that is drawn in a <code>View</code>'s <code>onDraw()</code> function. </p> <p>The corners of this shape are modified by any drag actions on this view through an overridden <code>onTouchEvent</code> function (which calls <code>invalidate()</code> to force the call to <code>onDraw()</code>).</p> <p>When initialising variables in <code>onDraw</code>, Eclipse shows a warning saying <strong>Avoid object allocations during draw/layout operations (preallocate and reuse instead)</strong>.</p> <p>This issue is explained as follows:</p> <p><strong>You should avoid allocating objects during a drawing or layout operation. These are called frequently, so a smooth UI can be interrupted by garbage collection pauses caused by the object allocations.</strong></p> <p><strong>The way this is generally handled is to allocate objects up front and to reuse them for each drawing operation</strong></p> <p>To do this I obviously have to be able to modify the corner radii as set in the constructor. The <a href="http://developer.android.com/reference/android/graphics/drawable/shapes/RoundRectShape.html" rel="nofollow" title="RoundedRectShape class">RoundedRectShape class</a> provides no setter (and I am pretty sure the related member variables are inaccessible).</p> <p>I know it is a small object and a minor issue, but how can I change these corners without reinitializing the Object when the only method the class provides for setting the radii of the rounded corners is through the constructor?</p> <p>Or is this just a case where doing the best thing will have to be replaced with doing what is possible?</p> <p>Thanks,</p> <p>P.S. Calling the constructor in the <code>onTouchEvent()</code> method will remove the warning but accomplishes absolutely nothing due to the fact that <code>onDraw()</code> is called every time through <code>invalidate()</code> anyway</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload