Created
March 9, 2016 07:52
-
-
Save sergenes/9ebee9d91c75b5cde7d7 to your computer and use it in GitHub Desktop.
Android - Fragment - show/hide keyboard event and move up the main layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rect visibleRect = new Rect(); | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
ViewGroup mMain = (ViewGroup) inflater.inflate(R.layout.select_cover_album, container, false); | |
mMain.getWindowVisibleDisplayFrame(visibleRect); | |
mMain.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { | |
@Override | |
public void onLayoutChange(View v, | |
int left, | |
int top, | |
int right, | |
int bottom, | |
int oldLeft, | |
int oldTop, | |
int oldRight, | |
int oldBottom) { | |
Rect r = new Rect(); | |
mMain.getWindowVisibleDisplayFrame(r); | |
if(r.height() < visibleRect.height()){ | |
mMain.postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
mMain.setY(-70); | |
} | |
}, 300); | |
} | |
if(r.height() == visibleRect.height() && mMain.getY() < 0){ | |
mMain.setY(0); | |
} | |
} | |
}); | |
return mMain; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment