Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I avoid getView() calls when measuring a GridView?
    primarykey
    data
    text
    <p>In my <code>Activity</code> I have a <code>GridView</code> inflated from this XML layout:</p> <pre><code>&lt;GridView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:columnWidth="@dimen/thumbnail_size" android:gravity="fill" android:horizontalSpacing="16dp" android:numColumns="auto_fit" android:stretchMode="columnWidth" android:verticalSpacing="16dp" /&gt; </code></pre> <p>The items inside it are <code>RelativeLayout</code>s, each set to a fixed height. While profiling my <code>Activity</code>, I noticed that when I enter an <code>ActionMode</code>, it causes a measure pass, which causes the <code>GridView</code> to be re-measured. The <code>GridView</code> in turn calls <code>getView()</code> on my adapter many times to measure all of the child views. This is unnecessary work, since (a) which children are visible hasn't changed, so it already has all the views it needs; and (b) none of the child views can change size.</p> <p>I know that <code>ListView</code> and <code>GridView</code> have lots of tricks they can do to avoid work in easy cases, and this seems like the kind of special case they might have an optimization for. Is there something I can set on the <code>GridView</code> to help it realise there's no need to call <code>getView()</code> again here? Alternatively, can I go higher up the stack and avoid the measure pass completely when entering and leaving an <code>ActionMode</code>? Just to be clear, the behaviour of my adapter is correct, and the <code>getView()</code> calls aren't causing me a problem: I just want my app to burn fewer cycles.</p> <p><strong>N.B.</strong> Even if I set the items to have fixed width as well as height, and replace the <code>GridView</code> with the following, it doesn't change the number of <code>getView()</code> calls (but it does make my <code>Activity</code> ugly).</p> <pre><code>&lt;GridView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="beforeDescendants" android:columnWidth="@dimen/thumbnail_size" android:horizontalSpacing="16dp" android:numColumns="3" android:stretchMode="none" android:verticalSpacing="16dp" /&gt; </code></pre>
    singulars
    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.
 

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