0

I want to add a clickable ImageView at the end of a multiline TextView, similarly like below example:

Text text text text text text text 
text text text. | Image |

I was able to implement this using an ImageSpan and ClickableSpan that I added to the TextView, But it's not able to return the exact clickable position. I want to show the Tooltip indicator at ImageView exactly. It should look like this below image. If the text in the TextView has multiple lines we have to show the Tooltip indicator at ImageView.

enter image description here

RajaReddy PolamReddy
  • 22,160
  • 18
  • 112
  • 166
  • https://stackoverflow.com/questions/11905486/how-get-coordinate-of-a-clickablespan-inside-a-textview – ADM Oct 19 '20 at 05:24

1 Answers1

0

Try this method :

First add drawable right image to the Textview:

Then override onTouch function:

@Override
    public boolean onTouch(View view, MotionEvent event) {
        final int DRAWABLE_LEFT = 0;
        final int DRAWABLE_TOP = 1;
        final int DRAWABLE_RIGHT = 2;
        final int DRAWABLE_BOTTOM = 3;

        if(event.getAction() == MotionEvent.ACTION_UP) {
            if(event.getRawX() >= (textview.getRight() - textview.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                // your click action here
                
                return true;
            }
        }
        return false;
    }
Shamir Kp
  • 478
  • 5
  • 9