Questions tagged [onmeasure]

77 questions
31
votes
2 answers

When is View.onMeasure() called?

When is View.onMeasure(int widthMeasureSpec, int heightMeasureSpec) called? I have an Activity that needs to perform an action after onMeasure has been called. My question is the same as the unanswered question posted here. The View documentation…
GregNash
  • 1,316
  • 1
  • 16
  • 25
22
votes
2 answers

Custom view's onMeasure: how to get width based on height

The previous version of my question was too wordy. People couldn't understand it, so the following is a complete rewrite. See the edit history if you are interested in the old version. A RelativeLayout parent sends MeasureSpecs to its child view's…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
12
votes
4 answers

RecyclerView#onMeasure() did not set the measured dimension by calling setMeasuredDimension()

I have a fragment with RecyclerView attached with the LinearSnapHelper so to get the view in the center and highlight it by scaling its size. it is working fine , but when pop this fragment from backstack on back press, it throws following…
11
votes
3 answers

Why is onMeasure() called twice in my custom View?

Below is my code for my custom View: XML layout:
linguowu
  • 111
  • 1
  • 6
7
votes
1 answer

Android: Set match_parent in custom view programmatically

I implemented a custom view where I can paint. I want to set it to MATCH_PARENT, so that it fills the screen independent of the screen orientation. When I change orientation to landscape it fills just 50% of width. I changed onMeasure() but there…
Kewitschka
  • 1,445
  • 1
  • 21
  • 35
7
votes
0 answers

How to call onMeasure when changing layout width and height

Hi I am working on canvas drawing. For that I am using custom view Activity(extends View) this view added into ScrollView in mainactivity(extends Activity) for scrolling canvas and my custom view width and height 700*3000 and at runtime custom view…
user123456
  • 123
  • 1
  • 15
6
votes
4 answers

SurfaceView onMeasure() did not set the measured dimension by calling setMeasuredDimension()

I have a SurfaceView. I just draw on it manually from an other Thread. It runs nicely. But after 10-20 minutes of running in average I get this exception: 01-14 08:51:25.000 3740-3740/com.myPackage E/AndroidRuntime﹕ FATAL EXCEPTION: main …
Tomi
  • 3,370
  • 1
  • 16
  • 26
5
votes
1 answer

Android ViewPager with dynamic height

I have a ViewPager to show some Fragments and swipe between them but the height of the ViewPager is dynamic based on the content. Assume I have multiple list that each list placed in one tab and by changing tabs the height of ViewPager should change…
4
votes
1 answer

Changing a DialogFragment Max_Height dynamically before onResume()?

I have a custom DialogFragment which I want to change its max_height dynamically according to its view's content size (wrap content). I don't want the update of the max_height to cause a jump in the UI so I planned to do it very early in the view's…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
4
votes
1 answer

Android: custom views get drawn at wrong x,y coordinates

I'm trying to create a custom view, inherit from view group, and layout custom sub-views inside this view group in a customized way. Basically I'm trying to create a calendar view similar to the one in outlook, where each event takes up screen…
user884248
  • 2,134
  • 3
  • 32
  • 57
3
votes
1 answer

how much can a scrollView scroll?

I have a layout with a scrollView inside it. How can I calculate what's the possible scroll size? I would think: (scroll's content desired height) - window.height = (invisible content height) But how do I get the scroll's content actual desired…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
3
votes
0 answers

OnMeasure get wrong value when in XML width and height are all fixed

I was developing a customized view when I encountered this problem. In the XML I set the layout_width & layout_height with fixed value 100dp. But in onMeaure() method I got widthMeasureSpec with measureMode EXACTLY, but heightMeasureSpec with…
3
votes
1 answer

onMeasure and onLayout of child views are not called after requestLayout on their parent

I'm trying understanding how Android measures and lays out views. I created a sample app with custom views and view groups. CustomViewGroup public class CustomViewGroup extends ViewGroup { private static final String LOG_TAG =…
Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
3
votes
1 answer

what's the difference between view and viewgroup for the method onMeasure()?

I am learning a custom component, and I find some difference in the view and viewgroup for the method onMeasure().For example, someone calls super.onMeasure, someone uses setMeasuredDimension at the end. Where is a difference? And measureChildren()…
Curry Cao
  • 31
  • 2
3
votes
0 answers

rewrite ViewGroup onMeasure, child match_parent not work

I have a custom Relativelayout with custom onMeasure method. code as below. @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int height =…
Cao Dongping
  • 969
  • 1
  • 12
  • 29
1
2 3 4 5 6