This yesterday wrote pretty close, too laborious, at present not I think better way to solve.
Also consulted a lot of friends of the information and blogs, but has not finished the effects I need.
Finally helpless use the following method:
1 Public classInputstatelinearlayoutextendslinearlayout{2 PrivateOnsizechangedlistener Listener;3 4 PublicInputstatelinearlayout (Context context) {5 Super(context);6 }7 8 PublicInputstatelinearlayout (Context context, AttributeSet attrs) {9 Super(context, attrs);Ten } One A PublicInputstatelinearlayout (context context, AttributeSet attrs,intdefstyleattr) { - Super(context, attrs, defstyleattr); - } the - @Override - protected voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) { - Super. Onmeasure (Widthmeasurespec, heightmeasurespec); + } - + @Override A protected voidOnLayout (BooleanChangedintLintTintRintb) { at Super. OnLayout (Changed, L, T, R, b); - } - - @Override - protected voidOnsizechanged (intWintHintOLDW,intOLDH) { - Super. Onsizechanged (W, H, OLDW, OLDH); in if(Listener! =NULL) { - listener.onsizechanged (W, H, OLDW, OLDH); to } + } - the Public voidSetonsizechangedlistener (Onsizechangedlistener listener) { * This. Listener =Listener; $ }Panax Notoginseng - /*** Callback interface when the activity main window size changes (this example is equivalent to the soft keyboard display is hidden when the callback interface)*/ the Public InterfaceOnsizechangedlistener { + Public voidOnsizechanged (intWintHintOLDW,intOLDH); A } the}
The above code does not say much, continue on the code:
1Mroot.setonsizechangedlistener (NewInputstatelinearlayout.onsizechangedlistener () {2 @Override3 Public voidOnsizechanged (intWintHintOLDW,intOLDH) {4 if(H>OLDH) {//Close5 //the logic you need to handle yourself.6 }7 }8});
Mroot is actually the root layout of this interface. Self-test, H>OLDH is closed and vice versa.
The above has temporarily completed my needs.
And then I used it, listening.
Viewtreeobserver
Although it is also possible, but it does not meet my needs.
Reprint please specify the source!
How to monitor the open and close of Android soft keyboard