Help, Fragment in how to get the width of the component
I want to be like QQ, QQ choose the kind of drop-down menu when you log on, but encountered a problem, I can not get the width of the component. Tried the whole life cycle, have access to the value 0. activity there onWindowFocusChanged () can get the width of the component lifecycle, Fragment there is no similar it? Currently think of two ideas, one is to get the width of the component in the Fragment of a life cycle, the other one is not able to obtain Fragment assembly in activity, and then () to obtain its components in width Activity of onWindowFocusChanged. Reply: What you said is not Fragment components inside the child controls? This is possible Reply:
Yes, what I have in Fragment inside a EditText, click there will be a ListView, but now the ListView's width is determined by the EditText, it is necessary to get this job EditText width Reply:
Say, is the life cycle can not get, I do not know what the life cycle of the width of the sub Fragment able to get inside the assembly, this is a problem Reply:
Not right, you click on the EditText, go to execute the above code, you can certainly get to this width. Because this time has been calculated EditText finished size.
mHandler.post (new Runnable () { @ Override public void run () { int width = mEditText.getMeasuredWidth (); } }, 20);
Reply: Activity layout with access to inside view as ah Reply:
. . . . . int width = mEditText.getMeasuredWidth ();
Say, is the life cycle can not get, I do not know what the life cycle of the width of the sub Fragment able to get inside the assembly, this is a problem
Not right, you click on the EditText, go to execute the above code, you can certainly get to this width. Because this time has been calculated EditText finished size.
mHandler.post (new Runnable () { @ Override public void run () { int width = mEditText.getMeasuredWidth (); } }, 20);
Well, I have to say is not to get the width of this component immediately after clicking ...... and I know how to get the ViewTreeObserver vto = parent1.getViewTreeObserver (); vto.addOnGlobalLayoutListener (new OnGlobalLayoutListener () {
@ Override public void onGlobalLayout () { / / TODO Auto-generated method stub pwidth1 = parent1.getWidth (); } }); So you can get the width of the component directly.
No comments:
Post a Comment