Example usage for android.widget TextView getHitRect

List of usage examples for android.widget TextView getHitRect

Introduction

In this page you can find the example usage for android.widget TextView getHitRect.

Prototype

public void getHitRect(Rect outRect) 

Source Link

Document

Hit rectangle in parent's coordinates

Usage

From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java

@BindingAdapter("increaseClickingArea")
public static void increaseClickingArea(TextView textView, float size) {
    // fork from http://stackoverflow.com/a/1343796
    View parent = (View) textView.getParent();
    // post in the parent's message queue to make sure the parent
    // lays out its children before we call View#getHitRect()
    parent.post(() -> {//from  ww  w  . ja va2s  .  c om
        final int halfSize = (int) (size / 2 + 0.5);
        Rect rect = new Rect();
        textView.getHitRect(rect);
        rect.top -= halfSize;
        rect.right += halfSize;
        rect.bottom += halfSize;
        rect.left -= halfSize;
        // use TouchDelegate to increase count's clicking area
        parent.setTouchDelegate(new TouchDelegate(rect, textView));
    });
}