开发者

Android: onSizeChanged, an example?

开发者 https://www.devze.com 2023-01-03 23:01 出处:网络
I want to use onSizeChange to detect the height difference i开发者_高级运维n a LinearLayout when the soft keyboard comes on screen. I want to issue fullScroll(View.FOCUS_DOWN); at that point. An examp

I want to use onSizeChange to detect the height difference i开发者_高级运维n 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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消