Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - v4 PagerTabStrip causes IllegalStateException - Must measure with an exact width
    primarykey
    data
    text
    <p>&lt; Edit ></p> <ol> <li><p>A new observation - I've tried the same ViewPager as stand alone Activity and as an AppWidget configuration view - and it crashes often as configuration view, while consistently runs well as a simple activity.</p></li> <li><p>Another observation - If the configuration layout is ViewPager as root, no crashes happened. if the ViewPager is embedded in FlowLayout or RelativeLayout - it crashes often.</p></li> </ol> <p>&lt; / Edit ></p> <p>I'm using v4 ViewPager with PagerTabStrip in my AppWidget configuration xml, and it works perfectly most of the time.</p> <p>However, I get this error (app crash) when some processing involved while loading the view:</p> <pre><code> java.lang.IllegalStateException: Must measure with an exact width at android.support.v4.view.PagerTitleStrip.onMeasure(PagerTitleStrip.java:428) at android.view.View.measure(View.java:8335) at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1350) at android.view.View.measure(View.java:8335) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017) ...etc... </code></pre> <p>A code snippet from android.support.v4.view.PagerTitleStrip.onMeasure() -</p> <pre><code>@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int widthMode = MeasureSpec.getMode(widthMeasureSpec); //... if (widthMode != MeasureSpec.EXACTLY) { throw new IllegalStateException("Must measure with an exact width"); } //... } </code></pre> <p>How could I control the widthMode??</p> <p>All the stack above is happening outside my code.</p> <p>In my code I've tried to rule out many factors, and eventually I may have managed to isolate a root cause:</p> <p>When I'm adding a mock "work" of 5 milis sleep per fragment (X30 fragments), I get the above error, and when removing it - the error seem gone. Tried moving the work to onCreate() - didn't make a difference</p> <pre><code>public static class TestFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.splash, container, false); try { Thread.sleep(5); // &lt;&lt; mock work causes quite consistent error } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.i(TAG, "..onCreateView"); return v; } } </code></pre> <p>The actual work I'm doing on my real adapter's fragment is minimal and can't be avoided (setting the initial values which later populate the data in a background thread). So I don't know how much more I can defer to a background thread.</p> <p>Does anyone have experience with this? Any idea why the above error occurs, and if it is possible to avoid it?</p> <p>For reference (Not sure if it's relevant):</p> <pre><code>&lt;LinearLayout ...&gt; &lt;android.support.v4.view.ViewPager android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:id="@+id/aw_pager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1.0" android:background="@drawable/dialog_full_holo_dark" android:fadingEdge="horizontal" android:fadingEdgeLength="40dp" &gt; &lt;android.support.v4.view.PagerTabStrip android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" /&gt; &lt;/android.support.v4.view.ViewPager&gt; &lt;/LinearLayout&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.
    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