use eclipse to set breakpoint at ViewRoot.scheduleTraversals(), you can find which action will result the infinitely onMeasure. Good luck!
On Friday, June 10, 2011 11:37:40 PM UTC+8, michael wrote: > > Hi, > > I'm trying to write a custom component that should scale as follows: > - some preferred size (e.g. 30) if wrap_content is specified > - fill parent if fill_parent is specified > - exact size if some size is specified. > > To do so, I have tried to override the onMeasure() method accordingly > (slightly adapted from > http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/), > > > as shown in the code below. This seems to work fine as long as I put > the component into a LinearLayout of a normal activity. However, once > I change the theme of the acitivty to dialog > (android:theme="@android:style/Theme.Dialog") in the manifest, my > onMeasure() method seems to be called infinitely, i.e. the Log.d() > output (see code) fills up my logcat. The component is drawn > correctly, though. Can somebody tell me, how I can fix this behavior, > such that onMeasure is called only once (or twice or so), even when > putting it into an activity with dialog theme? > > Thanks, > > Michael > > ------------------------- > Code: > > @Override > protected void onMeasure(int widthMeasureSpec, int > heightMeasureSpec) > { > Log.d(TAG, "Width spec: " + > MeasureSpec.toString(widthMeasureSpec)); > Log.d(TAG, "Height spec: " + > MeasureSpec.toString(heightMeasureSpec)); > > int widthMode = MeasureSpec.getMode(widthMeasureSpec); > int widthSize = MeasureSpec.getSize(widthMeasureSpec); > > int heightMode = MeasureSpec.getMode(heightMeasureSpec); > int heightSize = MeasureSpec.getSize(heightMeasureSpec); > > int chosenWidth = chooseDimension(widthMode, widthSize); > int chosenHeight = chooseDimension(heightMode, > heightSize); > > setMeasuredDimension(chosenWidth, chosenHeight); > } > > private int chooseDimension(int mode, int size) { > if (mode == MeasureSpec.AT_MOST || mode == > MeasureSpec.EXACTLY) { > return size; > } else { // (mode == MeasureSpec.UNSPECIFIED) > return getPreferredSize(); > } > } > > // in case there is no size specified > private int getPreferredSize() { > return 30; > } > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

