Noah Seidman
Noah Seidman

Reputation: 4409

Android: onSizeChanged, an example?

I want to use onSizeChange to detect the height difference in a LinearLayout when the soft keyboard comes on screen. I want to issue fullScroll(View.FOCUS_DOWN); at that point. An example would be greatly appreciated.

Upvotes: 1

Views: 6148

Answers (1)

JOG
JOG

Reputation: 5640

I do not understand your question, but here is an example. You already know that you should use onSizeChange, but exactly where do you run into problem?

public class SizeChangingLinearLayout extends LinearLayout {
    //...
    @Override
    protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld)
    {        
        if (yNew < yOld) 
            fullScroll(View.FOCUS_DOWN)
        else if (yNew > yOld) 
            fullScroll(View.FOCUS_UP)

        super.onSizeChanged(xNew, yNew, xOld, yOld);

    }
}

SizeChangingLinearLayout is the root view of the Activity. It only changes when the keyboard comes on, on landscape mode, and so on.

Does this help?

Upvotes: 1

Related Questions