• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps how to draw a view in click position

desatir7316

Newbie
Dec 25, 2014
35
2
hi there
i want to show a view in a position that user click
how to do it?
here is my code:

Code:
public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
         super.onTouchEvent(event);
        
         ImageView iv = new ImageView(this);
         iv.setVisibility(View.VISIBLE);
         iv.setImageResource(R.drawable.glass);     
         ((RelativeLayout) findViewById(R.id.container)).addView(iv);

         return true;
    }

thanks a lot
 
Last edited:
Hi,
I am not sure if this will help you. I am considering on this way.
Put RelativeLayout as main layout. Then you should get coordinates of user's click and when you will have this just add view on the RelativeLayout regarding of coordinates.

Hope that I've directed you on right way

best regards.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones