Causing onMeasure() to be called for an EditView

by poohtbear » Thu, 18 Feb 2010 01:24:28 GMT


Sponsored Links
 Using the hack doesn't work.
if i call to the setMeasuredDimension() with the dimensions i want
from the onLayout() of the layout it wont change the measured values.

So i need some help here :-)





--



Causing onMeasure() to be called for an EditView

by skink » Thu, 18 Feb 2010 02:11:33 GMT


 



how you call setMeasuredDimension ?

do you use MeasureSpec.makeMeasureSpec ?

pskink

--


Sponsored Links


Causing onMeasure() to be called for an EditView

by poohtbear » Thu, 18 Feb 2010 05:01:40 GMT


 setMeasuredDimension(int, int) takes the size you want the view to be,
this is why you have to call it in the end of onMeasure() the params
you writ are parameters to onMeasure() no setMEasureDimension().







--



Causing onMeasure() to be called for an EditView

by skink » Thu, 18 Feb 2010 05:13:53 GMT


 


my question was if you just pass parameters like 100. 50 which is
wrong way.

you have to pass values returned by MeasureSpec#makeMeasureSpec method

pskink

--



Causing onMeasure() to be called for an EditView

by skink » Thu, 18 Feb 2010 05:20:43 GMT


 



also i dont quite understand what you want to achieve? what is your
view hierarchy? can you post layout xml or if its created in runtime
its xml equivalent?

pskink

--



Causing onMeasure() to be called for an EditView

by skink » Thu, 18 Feb 2010 06:31:22 GMT


 




i'm sorry, yes, you are right, i mixed up onMeasure with
setMEasureDimension

again my apologies

pskink

--



Causing onMeasure() to be called for an EditView

by poohtbear » Thu, 18 Feb 2010 17:43:18 GMT


 the hirarchy ?
It's created in runtime

FramLayout
       |
       -------------CanvasView(extends view) - responsible for drawing
our UI, overrides onSizeChanged and onDraw.
       |
       ------------- EditText, used for binding our UI's focused
textFields to android's.

So when resize happens:
1. FrameLayout onMeasure is called.
   1.1 CanvasView onMeasure is called.
   1.2 EditText onMeasure is called <-- problem since new LayoutParams
are not set yet!
2. onLayout called on FrameLayout <-- here the FramLayout will use the
meausredWidth of Edit Text to lay it out.But the size is wrong
3. onSizeChanged is called on FrameLayout and CanvasView <--- here the
new LayoutParams are set for EditText.

what i need is step no 4: cause onMeasure to be called again, at least
on EditText and onLayout for FrameLayout, can't manage to do it.









--



Causing onMeasure() to be called for an EditView

by skink » Thu, 18 Feb 2010 18:26:51 GMT


 


ok, when at runtime, you create EditText, how you add it to
FrameLayout?

i mean what LayoutParams does your EditText have?

pskink

--



Causing onMeasure() to be called for an EditView

by poohtbear » Thu, 18 Feb 2010 18:40:41 GMT


 EditText and Canvas View are both created in the FrameLayout's C'tor
(sorry i forgot to to mention it's my own class inheriting from
FramLayout and not the original).
The first LAyoutParams i give EditText are w:0 h:0 x:0 y:0, each time
on resize is called and the item that the EditText is bounded to
changes it's size i take that size and set it in the margins and width
and height of the layoutParams.
The FramLayout is created in onCreate and added with setContentView()







--



Causing onMeasure() to be called for an EditView

by skink » Thu, 18 Feb 2010 19:16:07 GMT


 





can you post some code snippet how you add children to your custom
FrameLayout?

and why did you have to create your custom FrameLayout?

pskink

--



Causing onMeasure() to be called for an EditView

by poohtbear » Thu, 18 Feb 2010 21:52:20 GMT


 ere is the code snippet of the C'tor:
public class CanvasLayout extends FrameLayout
{
public CanvasView canvasView;

public CanvasLayout(Activity context)
{
super(context);
// setFocusableInTouchMode(true);

canvasView = new CanvasView(context);
canvasView.setFocusableInTouchMode(true);
addView(canvasView);

editControl = new MyEditText(context);
editControl.setBackgroundColor(Color.GREEN);
editControl.setVisibility(EditText.GONE);
editControl.setPadding(0, 0, 0, 0);
editControl.setFocusableInTouchMode(true);
FrameLayout.LayoutParams params = new
FrameLayout.LayoutParams(0, 0,Gravity.TOP|Gravity.LEFT);
params.setMargins(0, 0, 0, 0);
editControl.setLayoutParams(params);
// addView(editControl);
context.addContentView(editControl, params);
}


Basically i didn't have to create my own layout, it allowed later on
to use it's onSizeChnaged but basically i don't have to.

On Feb 18, 1:15pm, skink <psk...@gmail.com> wrote:

--



Causing onMeasure() to be called for an EditView

by skink » Thu, 18 Feb 2010 22:43:59 GMT


 




i don't understand why you use such strange LayoutParams params
why can't you simply do:

editControl = new EditText(context);
editControl.setFocusableInTouchMode(true);editControl.setBackgroundColor(Color.GREEN);
editControl.setVisibility(View.INVISIBLE);
addView(editControl);

?


ok so probably it will be better to use std FrameLayout

--



Causing onMeasure() to be called for an EditView

by poohtbear » Thu, 18 Feb 2010 22:57:41 GMT


 ah. the x,y secret.
I'm using FrameLayout to adjust my TextEdit is specific X,Y's on the
screen, it's possible sue to FrameLayout's margin layout.
I set the EditText in the screen according to my GUI's list items, so
i need the ability to set it to a specific place.
If not obsolete, i would have used AbsoluteLayout.








--



Causing onMeasure() to be called for an EditView

by skink » Thu, 18 Feb 2010 23:07:09 GMT


 


finally i understand: dont use FrameLayout at all

create custom Layout extending ViewGroup instead - it's quite easy

pskink

--



Other Threads

1. KAMERA NEXUS 1

Bro jgn post berulang2 untuk topik yg sama... thank you

--rc
King Klick desire2nexus
overclocked 1.13GHz!!




Apakah semua mengalami hal ini? Ada edek blur merah du kamera n1.

sent from my neXus 1

-- 
"Indonesian Android Community [id-android]"

2. (TabActivity) How to switch tab from within a "sub" activity

I'm sorry, but I don't understand what you mean :(

Actually, my "sub" activities are one MapActivity and one
ListActivity...

Thank you for your help






-- 

3. Petition: Google, please improve the Android Market.

4. Plans for Change (Was: Petition: Google, please improve the Android Market.)

5. Milestoner, Mod and Theme

6. growing assest allocations

7. Android, send me logs! - code library for detecting force-close and sending logs