Example usage for android.text Layout getLineBaseline

List of usage examples for android.text Layout getLineBaseline

Introduction

In this page you can find the example usage for android.text Layout getLineBaseline.

Prototype

public final int getLineBaseline(int line) 

Source Link

Document

Return the vertical position of the baseline of the specified line.

Usage

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterActivityContent.java

@Override
public void OnListViewResize(int w, int h, int oldw, int oldh) {
    // detect keyboard launching
    if (oldh > h) {
        if (composingItem != null) {
            // When keyboard is up, adjust the scolling such that the cursor is always visible
            final int firstIndex = messageCenterListView.getFirstVisiblePosition();
            int lastIndex = messageCenterListView.getLastVisiblePosition();
            View v = messageCenterListView.getChildAt(lastIndex - firstIndex);
            int top = (v == null) ? 0 : v.getTop();
            if (messageEditText != null) {
                int pos = messageEditText.getSelectionStart();
                Layout layout = messageEditText.getLayout();
                int line = layout.getLineForOffset(pos);
                int baseline = layout.getLineBaseline(line);
                int ascent = layout.getLineAscent(line);
                messageCenterViewHandler.sendMessage(messageCenterViewHandler.obtainMessage(MSG_SCROLL_FROM_TOP,
                        lastIndex, Math.max(top - (oldh - h), baseline - ascent)));
            }//  ww w. j av a 2s  .c  om
        }
    }
}