1

Is there any way to place the image on the last line of the TextView

I use setCompoundDrawablesWithIntrinsicBounds. Some ideas about it will be good.

Also i need to handle clicks on my image only. This behavior is represented by the following code :

   textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.info, 0);
                textView.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if(event.getAction() == MotionEvent.ACTION_UP) {
                            if(event.getRawX() >= textView.getRight() - textView.getTotalPaddingRight()){

                                listener.onAddressClicked(livingAreas);

                                return true;
                            }
                        }
                        return true;
                    }
                });
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
ManOfWar
  • 123
  • 1
  • 11

2 Answers2

1

Use SpannableString so that you can include image in your text. For code sample, check this question and answer

Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
1

With Text view you can set a drawable on a determinated position.

You can use this xml example:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableBottom="@drawable/image"
    android:text="blablabla"/>

Programmatically:

public void setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)

text_view.setCompoundDrawables(null, null, null, getDrawable(drawable_image_id));
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Lorenzo Vincenzi
  • 1,153
  • 1
  • 9
  • 26