среда, 17 ноября 2010 г.

View repaint workaround

I need hide footer in my Android application when soft keyboard appears.
Also I need show footer when soft keyboard disappears.

I create my own MyRelativeLayout and extend it from regular RelativeLayout.
Then I redefine one method:



@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);

final LinearLayout footer = (LinearLayout) findViewById(R.id.footer);
if (oldh>h) {
footer.setVisibility(RelativeLayout.GONE);
} else {
footer.setVisibility(RelativeLayout.VISIBLE);
}

//This is workaround for repaint footer
//It seems there are no another ways for repaint footer
final Handler handler = new Handler(new Callback() {

@Override
public boolean handleMessage(Message msg) {
footer.invalidate();
footer.requestLayout();
return true;
}
});
handler.sendEmptyMessage(0);

}